dotnet pack: Build a NuGet Package
dotnet pack builds a project and packages its output into a NuGet .nupkg ready to push to a feed.
pack turns a library into a publishable package. The version and metadata flags are what CI release jobs care about most.
What it does
dotnet pack builds the project and produces a .nupkg containing the assemblies plus the package metadata (id, version, dependencies) drawn from the project file. With --include-symbols it also emits a symbols package.
Common usage
dotnet pack -c Release -o ./artifacts
dotnet pack -c Release -p:Version=1.4.2 -o ./artifacts
dotnet pack -c Release --include-symbols --include-sourceOptions
| Flag | What it does |
|---|---|
| -c, --configuration <name> | Configuration to pack, normally Release |
| -o, --output <dir> | Directory to drop the .nupkg into |
| -p:Version=<x> | Set the package version (or PackageVersion) |
| --include-symbols | Also produce a .snupkg symbols package |
| --no-build | Pack without rebuilding (build in a prior step) |
| -p:PackageId=<id> | Override the package id |
In CI
Pass the version from your tag or build number with -p:Version=... rather than hardcoding it in the csproj. Output to a fixed -o directory so the subsequent dotnet nuget push can glob *.nupkg. Build once with -c Release and add --no-build to pack so you do not recompile.
Common errors in CI
NU5017 ("Cannot create a package that has no dependencies nor content") means nothing was packable; check IsPackable and that the project produces output. NU5039 ("The readme file ... does not exist") means the PackageReadmeFile path is wrong or not included as content. A missing PackageId/Version makes pack fall back to defaults like 1.0.0, which then collides on push.