NuGet CLI pack command (original) (raw)

Applies to: package creation • Supported versions: 2.7+

Creates a NuGet package based on the specified .nuspec or project file. The dotnet pack command (see dotnet Commands) and msbuild -t:pack (see MSBuild targets) may be used as alternates.

Important

Use dotnet pack or msbuild -t:pack for PackageReference based projects. Starting with NuGet version 6.5+, the pack command will error when attempting to pack these project types. Earlier versions would attempt to pack, but the generated package may not be correct. 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.

Usage

nuget pack <nuspecPath | projectPath> [options] [-Properties ...]

where <nuspecPath> and <projectPath> specify the .nuspec or project file, respectively.

Options

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.

The 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="1.3.3.2" 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 jQuery and microsoft-web-helpers but not netfx-Guard.

Suppressing pack warnings

While it is recommended that you resolve all NuGet warnings during your pack operations, in certain situations suppressing them is warranted.

You can achieve that in the following way:

nuget.exe pack package.nuspec -Properties NoWarn=NU5104

Examples

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"

Note

The pack command for SDK-style projects is not supported, use dotnet pack or msbuild -t:pack to pack this those projects instead.