This topic applies to: ✓ .NET Core SDK 1.x ✓ .NET Core SDK 2.x
dotnet pack - Packs the code into a NuGet package.
dotnet pack [<PROJECT>] [-c|--configuration] [--force] [--include-source] [--include-symbols] [--no-build] [--no-dependencies] [--no-restore] [-o|--output] [--runtime] [-s|--serviceable] [-v|--verbosity] [--version-suffix] dotnet pack [-h|--help]
dotnet pack command builds the project and creates NuGet packages. The result of this command is a NuGet package. If the
--include-symbols option is present, another package containing the debug symbols is created.
NuGet dependencies of the packed project are added to the .nuspec file, so they're properly resolved when the package is installed. Project-to-project references aren't packaged inside the project. Currently, you must have a package per project if you have project-to-project dependencies.
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.
You can provide MSBuild properties to the
dotnet pack command for the packing process. For more information, see NuGet metadata properties and the MSBuild Command-Line Reference. The Examples section shows how to use the MSBuild /p switch for a couple of different scenarios.
Starting with .NET Core 2.0, you don't have to run
dotnet restore because it's run implicitly by all commands, such as
dotnet build and
dotnet run, that require a restore to occur. It's still a valid command in certain scenarios where doing an explicit restore makes sense, such as continuous integration builds in Visual Studio Team Services or in build systems that need to explicitly control the time at which the restore occurs.
This command also supports the
dotnet restore options when passed in the long form (for example,
--source). Short form options, such as
-s, are not supported.
The project to pack. It's either a path to a csproj file or to a directory. If not specified, it defaults to the current directory.
Defines the build configuration. The default value is
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.
Prints out a short help for the command.
Includes the source files in the NuGet package. The sources files are included in the
src folder within the
Generates the symbols
Doesn't build the project before packing. It also implicit sets the
Ignores project-to-project references and only restores the root project.
Doesn't execute an implicit restore when running the command.
Places the built packages in the directory specified.
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 4.5.1 Supports Microsoft Security Updates for .NET NuGet Libraries.
Defines the value for the
$(VersionSuffix) MSBuild property in the project.
Sets the verbosity level of the command. Allowed values are
Pack the project in the current directory:
dotnet pack ~/projects/app1/project.csproj
Pack the project in the current directory and place the resulting packages into the
dotnet pack --output nupkgs
Pack the project in the current directory into the
nupkgs folder and skip the build step:
dotnet pack --no-build --output nupkgs
With the project's version suffix configured as
<VersionSuffix>$(VersionSuffix)</VersionSuffix> in the .csproj file, pack the current project and update the resulting package version with the given suffix:
dotnet pack --version-suffix "ci-1234"
Set the package version to
2.1.0 with the
PackageVersion MSBuild property:
dotnet pack /p:PackageVersion=2.1.0
Pack the project for a specific target framework:
dotnet pack /p:TargetFrameworks=net45
Pack the project and use a specific runtime (Windows 10) for the restore operation (.NET Core SDK 2.0 and later versions):
dotnet pack --runtime win10-x64