dotnet-pack
Packs the code into a NuGet package.
- Provided by: dotnet-host-10.0 (Version: 10.0.15-0ubuntu1~24.04.1)
- Source: dotnet10
- Report a bug
Packs the code into a NuGet package.
dotnet-pack - Packs the code into a NuGet package.
dotnet pack [<PROJECT>|<SOLUTION>|<NUSPEC>|<FILE>]
[--artifacts-path <ARTIFACTS_DIR>] [-c|--configuration <CONFIGURATION>]
[--disable-build-servers] [--force] [--include-source] [--include-symbols]
[--interactive] [--no-build] [--no-dependencies] [--no-restore] [--nologo]
[-o|--output <OUTPUT_DIRECTORY>] [-p|--property:<PROPERTYNAME>=<VALUE>]
[--runtime <RUNTIME_IDENTIFIER>]
[-s|--serviceable] [--tl:[auto|on|off]] [-v|--verbosity <LEVEL>]
[--version <VERSION>] [--version-suffix <VERSION_SUFFIX>]
dotnet pack -h|--help
The dotnet pack command builds the project and creates NuGet packages. The result of this command is a NuGet package (that is, a .nupkg file).
Starting with .NET 10, you can also pass a .nuspec file or a file-based app (.cs file) directly as the argument. When you pass a .nuspec file, dotnet pack creates the package from the .nuspec file without requiring a project file and without running MSBuild. When you pass a file-based app, dotnet pack packs it without a project file.
If you want to generate a package that contains the debug symbols, you have two options available:
NuGet dependencies of the packed project are added to the .nuspec file, so they’re properly resolved when the package is installed. If the packed project has references to other projects, the other projects aren’t included in the package. Currently, you must have a package per project if you have project-to-project dependencies.
By default, dotnet pack builds the project first. If you wish to avoid this behavior, pass the --no-build option. This option is often useful in Continuous Integration (CI) build scenarios where you know the code was previously built.
In some cases, the implicit build cannot be performed. This can occur when GeneratePackageOnBuild is set, to avoid a cyclic dependency between build and pack targets. The build can also fail if there is a locked file or other issue.
Web projects aren’t packable.
You don’t have to run dotnet restore because it’s run implicitly by all commands that require a restore to occur, such as dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To disable implicit restore, use the --no-restore option.
The dotnet restore command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.
For information about how to manage NuGet feeds, see the dotnet restore documentation.
This command supports the dotnet restore options when passed in the long form (for example, --source). Short form options, such as -s, are not supported.
When you run this command, it initiates an asynchronous background download of advertising manifests for workloads. If the download is still running when this command finishes, the download is stopped. For more information, see Advertising manifests.
PROJECT | SOLUTION | NUSPEC | FILE
The project, solution, .nuspec file, or file-based app to pack.
If not specified, the command searches the current directory for a project or solution file.
--artifacts-path <ARTIFACTS_DIR>
All build output files from the executed command will go in subfolders under the specified path, separated by project. For more information see Artifacts Output Layout. This option and the value provided must be explicitly cascaded in any dotnet command that depends on the output of another dotnet command, for example, when using dotnet build --no-restore and dotnet publish --no-build. Available since .NET 8 SDK.
-c|--configuration <CONFIGURATION>
Defines the build configuration. If you’re developing with the .NET 8 SDK or a later version, the command uses the Release configuration by default for projects whose TargetFramework is set to net8.0 or a later version. The default build configuration is Debug for earlier versions of the SDK and for earlier target frameworks. You can override the default in project settings or by using this option. For more information, see `dotnet publish' uses Release configuration and `dotnet pack' uses Release configuration.
--disable-build-servers
Forces the command to ignore any persistent build servers. This option provides a consistent way to disable all use of build caching, which forces a build from scratch. A build that doesn’t rely on caches is useful when the caches might be corrupted or incorrect for some reason. Available since .NET 7 SDK.
Forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is the same as deleting the project.assets.json file.
Includes the debug symbols NuGet packages in addition to the regular NuGet packages in the output directory. The sources files are included in the src folder within the symbols package.
Includes the debug symbols NuGet packages in addition to the regular NuGet packages in the output directory.
--interactive
Allows the command to stop and wait for user input or action. For example, to complete authentication.
Doesn’t build the project before packing. It also implicitly sets the --no-restore flag.
Ignores project-to-project references and only restores the root project.
Doesn’t execute an implicit restore when running the command.
Doesn’t display the startup banner or the copyright message.
Places the built packages in the directory specified.
In the 7.0.200 SDK, if you specify the --output option when running this command on a solution, the CLI will emit an error. This is a regression and was fixed in 7.0.201 and later versions of the .NET SDK.
Sets one or more MSBuild properties. When packing a .nuspec file directly, the properties are used for token replacement in the .nuspec file rather than as MSBuild properties. Specify multiple properties delimited by semicolons or by repeating the option:
--property:<NAME1>=<VALUE1>;<NAME2>=<VALUE2>
--property:<NAME1>=<VALUE1> --property:<NAME2>=<VALUE2>
For more information, see NuGet pack target properties and MSBuild command-line reference.
Specifies the target runtime to restore packages for. For a list of Runtime Identifiers (RIDs), see the RID catalog.
Sets the serviceable flag in the package. For more information, see .NET Blog: .NET Framework 4.5.1 Supports Microsoft Security Updates for .NET NuGet Libraries (https://aka.ms/nupkgservicing).
--tl:[auto|on|off]
Specifies whether Terminal Logger should be used for the build output. The default is auto, which first verifies the environment before enabling terminal logging. The environment check verifies that the terminal is capable of using modern output features and isn’t using a redirected standard output before enabling the new logger. on skips the environment check and enables terminal logging. off skips the environment check and uses the default console logger.
Terminal Logger shows you the restore phase followed by the build phase. During each phase, the currently building projects appear at the bottom of the terminal. Each project that’s building outputs both the MSBuild target currently being built and the amount of time spent on that target. You can search this information to learn more about the build. When a project is finished building, a single “build completed” section is written that captures:
This option is available starting in .NET 8.
-v|--verbosity <LEVEL>
Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. For more information, see <xref:Microsoft.Build.Framework.LoggerVerbosity>.
The version of the package to create. When packing a .nuspec file, overrides the version number in the .nuspec file.
Available starting in .NET 10.
Defines the value for the VersionSuffix MSBuild property. The effect of this property on the package version depends on the values of the Version and VersionPrefix properties, as shown in the following table:
| Properties with values | Package version |
| None | 1.0.0 |
| Version | $(Version) |
| VersionPrefix only | $(VersionPrefix) |
| VersionSuffix only | 1.0.0-$(VersionSuffix) |
| VersionPrefix and VersionSuffix | $(VersionPrefix)-$(VersionSuffix) |
If you want to use --version-suffix, specify VersionPrefix and not Version in the project file. For example, if VersionPrefix is 0.1.2 and you pass --version-suffix rc.1 to dotnet pack, the package version will be 0.1.2-rc.1.
If Version has a value and you pass --version-suffix to dotnet pack, the value specified for --version-suffix is ignored.
-?|-h|--help
Prints out a description of how to use the command.
dotnet pack
dotnet pack ~/projects/app1/project.csproj
dotnet pack --output nupkgs
dotnet pack --no-build --output nupkgs
dotnet pack --version-suffix "ci-1234"
dotnet pack -p:PackageVersion=2.1.0
dotnet pack -p:TargetFrameworks=net45
dotnet pack --runtime win-x64
dotnet pack -p:Deterministic=true -p:DeterministicTimestamp="2026-12-19T16:39:57-08:00"
dotnet pack ~/projects/app1/project.csproj -p:NuspecFile=~/projects/app1/project.nuspec -p:NuspecBasePath=~/projects/app1/nuget
For information about how to use NuspecFile, NuspecBasePath, and NuspecProperties, see the following resources:
dotnet pack MyPackage.nuspec --output ./artifacts
```dotnetcli
dotnet pack MyPackage.nuspec --version 1.2.3 --output ./artifacts
dotnet pack MyPackage.nuspec --property:Version=1.2.3 --property:Configuration=Release --output ./artifacts