pack command (NuGet CLI)
Applies to: package creation • Supported versions: 2.7+
dotnet pack or
msbuild -t:pack for PackageReference based projects.
Under Mono, creating a package from a project file is not supported. You also need to adjust non-local paths in the
.nuspec file to Unix-style paths, as nuget.exe doesn't convert Windows pathnames itself.
nuget pack <nuspecPath | projectPath> [options] [-Properties ...]
<projectPath> specify the
.nuspec or project file, respectively.
|BasePath||Sets the base path of the files defined in the .nuspec file.|
|Build||Specifies that the project should be built before building the package.|
|Exclude||Specifies one or more wildcard patterns to exclude when creating a package. To specify more than one pattern, repeat the -Exclude flag. See example below.|
|ExcludeEmptyDirectories||Prevents inclusion of empty directories when building the package.|
|ForceEnglishOutput||(3.5+) Forces nuget.exe to run using an invariant, English-based culture.|
|ConfigFile||Specify the configuration file for the pack command.|
|Help||Displays help information for the command.|
|IncludeReferencedProjects||Indicates that the built package should include referenced projects either as dependencies or as part of the package. If a referenced project has a corresponding
|MinClientVersion||Set the minClientVersion attribute for the created package. This value will override the value of the existing minClientVersion attribute (if any) in the
|MSBuildPath||(4.0+) Specifies the path of MSBuild to use with the command, taking precedence over
|MSBuildVersion||(3.2+) Specifies the version of MSBuild to be used with this command. Supported values are 4, 12, 14, 15.1, 15.3, 15.4, 15.5, 15.6, 15.7, 15.8, 15.9. By default the MSBuild in your path is picked, otherwise it defaults to the highest installed version of MSBuild.|
|NoDefaultExcludes||Prevents default exclusion of NuGet package files and files and folders starting with a dot, such as
|NoPackageAnalysis||Specifies that pack should not run package analysis after building the package.|
|OutputDirectory||Specifies the folder in which the created package is stored. If no folder is specified, the current folder is used.|
|Properties||Should appear last on the command line after other options. Specifies a list of properties that override values in the project file; see Common MSBuild Project Properties for property names. The Properties argument here is a list of token=value pairs, separated by semicolons, where each occurrence of
|Suffix||(3.4.4+) Appends a suffix to the internally generated version number, typically used for appending build or other pre-release identifiers. For example, using
|Symbols||Specifies that the package contains sources and symbols. When used with a
|Tool||Specifies that the output files of the project should be placed in the
|Verbosity||Specifies the amount of detail displayed in the output: normal, quiet, detailed.|
|Version||Overrides the version number from the
Also see Environment variables
Excluding development dependencies
Some NuGet packages are useful as development dependencies, which help you author your own library, but aren't necessarily needed as actual package dependencies.
pack command will ignore
package entries in
packages.config that have the
developmentDependency attribute set to
true. These entries will not be include as a dependencies in the created package.
For example, consider the following
packages.config file in the source project:
<?xml version="1.0" encoding="utf-8"?> <packages> <package id="jQuery" version="1.5.2" /> <package id="netfx-Guard" version="220.127.116.11" developmentDependency="true" /> <package id="microsoft-web-helpers" version="1.15" /> </packages>
For this project, the package created by
nuget pack will have a dependency on
microsoft-web-helpers but not
nuget pack nuget pack foo.nuspec nuget pack foo.csproj nuget pack foo.csproj -Properties Configuration=Release nuget pack foo.csproj -Build -Symbols -Properties owners=janedoe,xiaop;version="1.0.5" # Create a package from project foo.csproj, using MSBuild version 12 to build the project nuget pack foo.csproj -Build -Symbols -MSBuildVersion 12 -Properties owners=janedoe,xiaop;version="1.0.5" # Create a package from project foo.nuspec and the corresponding symbol package using the new recommended format .snupkg nuget pack foo.nuspec -Symbols -SymbolPackageFormat snupkg nuget pack foo.nuspec -Version 2.1.0 nuget pack foo.nuspec -Version 1.0.0 -MinClientVersion 2.5 nuget pack Package.nuspec -exclude "*.exe" -exclude "*.bat"