With the .NET 10 SDK, what does dotnet pack produce for a class library, and what do PackageId, Version, Authors and IsPackable default to?
answer
- a .nupkg in bin/Release
- PackageId falls back to AssemblyName
- Version comes from VersionPrefix 1.0.0
- Authors defaults to the assembly name
- test projects are not packable
basics
~20 sdotnet pack builds the project in Release and writes <PackageId>.<version>.nupkg to bin/Release. PackageId defaults to the assembly name, the version to Version (1.0.0 unless set), Authors to the assembly name, and IsPackable is true except for test projects.
solid answer
~40 s`dotnet pack` builds the library and runs NuGet's pack target, which writes a `.nupkg` — a zip holding the generated `.nuspec`, the assemblies under `lib/<tfm>/` and the declared metadata. Because `PackRelease` defaults to `true`, the CLI packs **Release** and drops the file in `bin/Release/` (`PackageOutputPath` is `$(BaseOutputPath)$(Configuration)\`). Defaults come from the targets: `PackageId` = `$(AssemblyName)`, `PackageVersion` = `$(Version)`, which is `VersionPrefix` 1.0.0 plus any `VersionSuffix`; `Authors` = `$(AssemblyName)`; the description falls back to `Package Description`. `IsPackable` is `true` unless the project is a test project or a testing-platform app, where it becomes `false`. `PackageReference` items turn into nuspec dependencies, and a `ProjectReference` becomes a dependency on that project's package. .NET 10 adds `dotnet pack --version` to set `PackageVersion` directly.
code
xml · 9 lines<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<PackageId>Shared.Validation</PackageId>
<VersionPrefix>2.3.0</VersionPrefix>
<Authors>Platform team</Authors>
<Description>Validation rules shared by the lending services.</Description>
</PropertyGroup>
</Project>go deeper
Recall that dotnet pack writes a .nupkg, that PackageId comes from the assembly name and the version from Version, and where the file lands.
Explain each default and its source, how VersionPrefix, VersionSuffix, PackageVersion and the .NET 10 --version option interact, and how references become dependencies.
Set package identity and metadata deliberately, keep non-libraries unpackable, and notice where the docs and the SDK targets disagree before trusting either.
Decide how a portfolio of internal libraries is versioned and packed in CI, and who owns package identity once consumers depend on it.
## What dotnet pack does `dotnet pack` is how an SDK-style project becomes a NuGet package. It restores and builds the project (unless `--no-build` is given) and then runs NuGet's **pack** target, which generates a `.nuspec` from MSBuild properties and zips it with the build output into a `.nupkg`. The team that owns a shared validation library used by several internal services runs: ```bash dotnet pack Shared.Validation/Shared.Validation.csproj -o ./artifacts ``` and gets `Shared.Validation.1.0.0.nupkg` in `./artifacts`. ## Where the defaults come from Every package field has an MSBuild property behind it, and the SDK and `NuGet.Build.Tasks.Pack.targets` fill the empty ones: | Property | Default when unset | Source of the default | |---|---|---| | `PackageId` | `$(AssemblyName)` | pack targets | | `PackageVersion` | `$(Version)` | pack targets | | `Version` | `$(VersionPrefix)`, plus `-$(VersionSuffix)` if set | SDK assembly-info targets | | `VersionPrefix` | `1.0.0` | SDK assembly-info targets | | `Authors` | `$(AssemblyName)` | SDK assembly-info targets | | `PackageDescription` | `$(Description)`, else `Package Description` | pack targets | | `IsPackable` | `false` for test projects, else `true` | pack targets | | `PackageOutputPath` | `$(BaseOutputPath)$(Configuration)\` | pack targets | Two of these contradict the reference docs, and the source wins. The NuGet docs table says `Authors` defaults to the current user name; the SDK sets it to the assembly name. The docs also say `IsPackable` defaults to `true`; the targets make it `false` when `IsTestProject` or `IsTestingPlatformApplication` is `true`, so packing a whole solution skips test projects. ## Configuration and output - **Release by default.** `PackRelease` defaults to `true`, so the CLI packs the Release configuration unless you pass `-c Debug`. Packages built in Debug by accident used to be a common mistake. - **Output folder.** Without `-o`, the package lands in `bin/Release/`, not under the target-framework subfolder. - **Not on every build.** `GeneratePackageOnBuild` defaults to `false`; set it to `true` only if every build should also produce a package. ## Setting the version There are several equivalent levers, from most to least explicit: 1. `dotnet pack --version 2.3.0` — new in .NET 10; it sets `PackageVersion`. 2. `-p:PackageVersion=2.3.0` on any SDK version. 3. `<Version>` in the project, or `<VersionPrefix>` with `--version-suffix beta.1` for prereleases such as `2.3.0-beta.1`. Setting `PackageVersion` overrides the prefix and suffix. Because the package version is the contract consumers resolve against, CI usually computes it rather than leaving the 1.0.0 default in place. ## What goes inside - `lib/<tfm>/Shared.Validation.dll` and its XML documentation file if one is generated — pack copies `.dll`, `.exe`, `.winmd`, `.json`, `.pri` and `.xml` build outputs. - A `.nuspec` with id, version, authors, description, license and repository metadata. - A dependency group per target framework listing every `PackageReference` that is not fully private, and a dependency on the package of every `ProjectReference`. `SuppressDependenciesWhenPacking` removes all dependencies, which is almost never what a library wants. ## Packing in a pipeline A release job for the validation library usually separates build and pack so the tested binaries are the packed ones: 1. `dotnet build -c Release` once, run the tests against that output. 2. `dotnet pack -c Release --no-build -o artifacts --version 2.3.0` to package exactly those binaries; `--no-build` also implies no restore. 3. Keep the `.nupkg` as the build artifact and push that same file later. The SDK can also check the package as it is produced: with `EnablePackageValidation` set to `true`, a `RunPackageValidation` step runs after `Pack`, and `PackageValidationBaselineVersion` makes it compare the new package's API with a previously released version, so an accidental breaking change fails the pack instead of reaching consumers. ## Common traps - Shipping with `Package Description` and an author equal to the assembly name because nobody set the metadata. - Packing an application or test project by accident; set `IsPackable` to `false` explicitly on anything that is not a library. - Forgetting that the id is permanent on a public feed: renaming `PackageId` later creates a different package rather than a new version of the old one.
- Why might dotnet pack on a solution produce no package for the test project?NuGet's pack targets set `IsPackable` to `false` when `IsTestProject` or `IsTestingPlatformApplication` is `true` and the project has not set `IsPackable` itself. Test SDKs set those flags, so a solution-wide pack skips them; the docs' claim that the default is always `true` is out of date.
- What becomes of a ProjectReference when the library is packed?It becomes a package dependency in the nuspec, on the referenced project's `PackageId` and version, so that project must also be packed and published. The referenced assembly is not copied into your package unless you take extra steps; NuGet treats project references as package references by default.
- PackageId defaults to the folder name of the solution.
- dotnet pack uses the Debug configuration unless told otherwise.
- Authors defaults to the logged-in user's name, as the docs say.
- Test projects are packed like any other project unless excluded by hand.
- dotnet pack copies ProjectReference assemblies into the package's lib folder.
Assumes the .NET 10.0.400 SDK with NuGet 7; dotnet pack --version arrived in .NET 10, PackRelease has made Release the CLI default since .NET 8, and the Authors and IsPackable defaults are read from the pinned targets rather than the docs.