dotnet-pack - Man Page

Packs the code into a NuGet package.

dotnet pack

This article applies to: ✔️ .NET Core 3.1 SDK and later versions

Synopsis

dotnet pack [<PROJECT>|<SOLUTION>] [--artifacts-path <ARTIFACTS_DIR>]
    [-c|--configuration <CONFIGURATION>] [--force]
    [--include-source] [--include-symbols] [--interactive]
    [--no-build] [--no-dependencies] [--no-restore] [--nologo]
    [-o|--output <OUTPUT_DIRECTORY>] [--runtime <RUNTIME_IDENTIFIER>]
    [-s|--serviceable] [--tl:[auto|on|off]] [-v|--verbosity <LEVEL>]
    [--version-suffix <VERSION_SUFFIX>]

dotnet pack -h|--help

Description

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).

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.

You can provide MSBuild properties to the dotnet pack command for the packing process. For more information, see NuGet pack target properties and the MSBuild Command-Line Reference. The Examples section shows how to use the MSBuild -p switch for a couple of different scenarios.

Web projects aren’t packable.

Implicit restore

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.

Workload manifest downloads

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.

Arguments

PROJECT | SOLUTION

The project or solution to pack. It’s either a path to a csproj, vbproj, or fsproj file, or to a solution file or directory. If not specified, the command searches the current directory for a project or solution file.

Options

Examples

Info

2024-10-02 .NET Documentation