Skip to main content

Nuget Build and Publish Scripts for Multiple Targets

Here’s a set of basic command line steps to run, to generate a nuget package for a library or an executable.

NOTE: These statements are for projects that target multiple runtimes. So, they can be simplified for a single runtime or single target framework.

For a Library

To build, package, and publish a library, a variant of these statements is needed:

// Build the library...
dotnet build "./NETCore_Common_NET6.csproj" -c DebugLinux --runtime linux-x64 --no-self-contained
dotnet build "./NETCore_Common_NET6.csproj" -c DebugWin --runtime win-x64 --no-self-contained

To// createCreate the nugetnupkg packagewith filepdb from built files.included...
D:\Programs\nuget\nuget.exe pack <nuspecfilepath>./NETCore_Common_NET6.nuspec -IncludeReferencedProjects -symbolsOutputDirectory ./Publish -Verbosity detailed"

// Publish the nupkg with pdb included...
dotnet nuget push -s https://buildtools.ogsofttech.com:8079/v3/index.json <nupkg path>

// Create the nupkg and symbol package...
nuget.exe pack <nuspecfilepath>.nuspec -IncludeReferencedProjects -Symbols -SymbolPackageFormat snupkg -OutputDirectory bin./Publish -Verbosity detailed

To// publishPublish nugetthe symbol package...
dotnet nuget push -s https://buildtools.ogsofttech.com:8079/v3/index.json "P:\Projects\NETCore<symbol SoftwareLibraries\NETCorepackage SoftwareLibraries\NETCore_Common_NET6\bin\NETCore_Common_NET6.1.4.6.nupkg"path>

For an Application

To build an executable, these statements will build and publish the application binaries:

// Build the main assembly for windows and linux...
dotnet build "./NETCore_Common_NET6.csproj" -c DebugLinux --runtime linux-x64 --no-self-contained
dotnet build "./NETCore_Common_NET6.csproj" -c DebugWin --runtime win-x64 --no-self-contained

// Publish the main assembly for both Windows and Linux...
dotnet publish "./NETCore_Common_NET6.csproj" -c DebugWin -o bin/publish/debug/win-x64 /p:DefineConstants=Windows --runtime win-x64 --no-self-contained
dotnet publish "./NETCore_Common_NET6.csproj" -c DebugLinux -o bin/publish/debug/linux-x64 /p:DefineConstants=Linux --runtime linux-x64 --no-self-contained