Edit in GitHub or Give Feedback

NuGet.exe CLI Reference

Page generated on 9/26/2016

NuGet Command Line Interface (CLI) is used to create, publish, manage and download your packages from the command line instead of from Visual Studio. The Install Guide gives an overview of the various ways to install nuget.exe on your box.

install

Downloads and extracts a package using the specified sources. If no sources are specified sources from NuGet.Config will be used.

This command does not modify the project file, it behaves similar to restore in that it only adds packages to disk. Projects using packages.config may only install new packages using Visual Studio.

Usage

nuget install <packageId|pathToPackagesConfig> [options]

Specify the id and optionally the version of the package to install. If a path to a packages.config file is used instead of an id, all the packages it contains will be restored.

Options

configfile (v2.5) Specifies the NuGet configuration file. If not specified NuGet.Config is used.
excludeversion If set, the destination directory will contain only the package name, not the version number.
fileconflictaction (v2.5) Specifies the action to take, when asked to overwrite or ignore existing files referenced by the project: overwrite, ignore, none.
help Displays help information for the install command.
nocache Disables looking up packages from local machine cache.
noninteractive Do not prompt for user input or confirmations.
outputdirectory Specifies the directory in which packages will be installed. If none are specified, the current directory is used.
prerelease Allows prerelease packages to be installed. This flag is not required when restoring packages with packages.config.
requireconsent Checks if package restore consent is granted before downloading a package.
solutiondirectory Specifies the solution root for package restore.
source A list of package sources to use for the installation.
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.
version The version of the package to install.

Examples

nuget install elmah

nuget install packages.config

nuget install ninject -o c:\foo

update

Updates packages to the latest available versions. The update command requires a Packages folder. It is recommended to run 'nuget.exe Restore' before running the Update command.

The update command will download and extract all new packages to the packages folders. Assembly references will be updated in the project file, however this is limited to only existing references. If a new package has an added assembly it will not be added as part of the update command. New package dependencies will also not have their assembly references added. To perform a complete update use Visual Studio.

This command can also be used to update nuget.exe itself using the -self flag.

Usage

nuget update [packages.config|solution] [options]

Options

configfile (v2.5) Specifies the NuGet configuration file. If not specified NuGet.config is used.
fileconflictactions (v2.5) Specifies the action to take, when asked to overwrite or ignore existing files referenced by the project: overwrite, ignore, none.
help Displays help information for the update command.
id A list of package ids to update.
msbuildversion Specifies the version of MSBuild to be used with this command. Supported values are 4, 12, 14, 15. By default the MSBuild in your path is picked, otherwise it defaults to the highest installed version of MSBuild.
noninteractive Do not prompt for user input or confirmations.
prerelease Allows updating to prerelease versions. This flag is not required when updating prerelease packages that are already installed.
repositorypath Path to the local folder where packages are installed.
safe Specifies that only updates with the highest version available within the same major and minor version as the installed package will be installed.
self (v1.4) Updates nuget.exe to the newest version available from the server.
source A list of package sources to update from.
verbose Shows verbose output while updating.
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.
Version The version of the package to update. Requires -Id to contain exactly one package id.

Examples

nuget update

nuget update -safe

nuget update -self

# update packages installed in solution.sln, using msbuild version 14.0 to load the solution and its project(s).
nuget update solution.sln -MSBuildVersion 14

restore

(v2.7) Downloads and unzips (restores) any packages missing from the packages folder.

(v3.3.0) Generates a project.lock.json file for projects using project.json.

Usage

nuget restore [solution|packages.config|project.json] [options]

Options

configfile Specifies the user specific configuration file. If omitted, nuget.config is used instead.
disableparallelprocessing Disable parallel nuget project restores and package downloads.
help Displays help information for the restore command.
msbuildversion Specifies the version of MSBuild to be used with this command. Supported values are 4, 12, 14, 15. By default the MSBuild in your path is picked, otherwise it defaults to the highest installed version of MSBuild.
nocache Disables using the machine cache as the first package source.
noninteractive Do not prompt for user input or confirmations.
outputdirectory Specifies the packages directory. Identical to packagesdirectory.
packagesdirectory Specifies the packages directory. Identical to outputdirectory.
requireconsent Checks if package restore consent is granted before restoring a package.
solutiondirectory Specifies the solution directory. Not valid when restoring packages for a solution.
source A list of package sources to use for the install.
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.

Restore Notes

The restore command is executed in the following steps:

  1. Determine the operation mode of the restore command.

    • If <solution> is specified, nuget restores packages for the solution's projects. In this case, nuget needs to locate the solution file.
      • If <solution> is a file, that file is used as the solution file.
      • If <solution> is a directory, then nuget searches for a *.sln file in that directory. If exactly one file is found, that file is used as the solution file. Otherwise, nuget displays an error message and exits.
      • If the -solutiondirectory option is specified, nuget will display an error and exit.
    • If <packages.config file> is specified, nuget restores the packages listed in the packages.config file.
    • If <project.json file> is specified, nuget restores packages listed in the project.json file, resolves the dependencies of those packages and installs those dependent packages as well.
    • If no argument is provided,
      • nuget first looks for solution files in the current directory. If there is just one solution file, nuget will restore packages for that solution. If there are multiple solution files, an error message is displayed and nuget exits.
      • If there are no solution files, nuget then searches for a packages.config file or project.json file in the current directory. If either file exists, nuget will restore packages listed in that file.
      • If there are no solution files or packages.config file in the current directory, an error message is displayed and nuget exits.
  2. If nuget is restoring packages for a solution file, $(SolutionDir).nuget is used as the starting directory. If nuget is restoring packages from packages.config file, the directory of that file is used as the starting directory.

  3. Calculate the packages directory. Nuget will use the following criteria, and as soon as one criteria is met, that directory is used.

    • If project.json is specified, %userprofile%.nuget\packages is used as the packages directory.
    • If -PackagesDirectory <packagesDirectory> is specified, <packagesDirectory> is used as the packages directory.
    • If the repositoryPath key is found the nuget.config file, its value is used as the packages directory.
    • If -SolutionDirectory <solutionDirectory> is specified, <solutionDirectory>\packages is used as the packages directory.
    • If nuget is restoring packages for a solution, the $(SolutionDir)\packages is used as the packages directory.
    • If the packages directory cannot be determined, an error message is displayed and nuget exits.
  4. When nuget is restoring packages for a solution, nuget takes the following steps:

    • Loads the solution file.
    • Restores solution level packages listed in $(SolutionDir)\.nuget\packages.config file.
    • Restoes packages listed in $(ProjectDir)\packages.config file.
      • For each package specified, restore the package in parallel unless -disableparallelprocessing is specified.
      • Downloads the package from the sources.
      • Unzips the packages to the packages directory.

Examples

# Restore packages for a solution file
nuget restore a.sln

# Restore packages for a solution file, using msbuild version 14.0 to load the solution and its project(s)
nuget restore a.sln -MSBuildVersion 14

# Restore packages for a project's packages.config file, with the packages folder at the parent
nuget restore proj1\packages.config -PackagesDirectory ..\packages

# Restore packages for the solution in the current folder, specifying package sources
nuget restore -source "https://www.nuget.org/api/v2;https://www.myget.org/F/nuget"

delete

Deletes or unlists a package from the server. For NuGet.org, the action is to unlist the package.

Usage

nuget delete <package Id> <package version> [API Key] [options]

Specify the Id and version of the package to delete or unlist a package from the server.

This behavior varies depending on the source, nuget.org for example does not allow deletes and will unlist the package instead. For local folders the package will be deleted.

Options

apikey The API key for the server.
configfile (v2.5) Specifies the user specific configuration file. If omitted, nuget.config is used instead.
help Displays help information for the delete command.
noninteractive Do not prompt for user input or confirmations.
source Specifies the server URL. Supported URL's for nuget.org include - https://www.nuget.org, https://www.nuget.org/api/v3, https://www.nuget.org/api/v2/package. For private feeds, substitute the host name (e.g %hostname%/api/v3).
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.

Examples

nuget delete MyPackage 1.0

nuget delete MyPackage 1.0 -NonInteractive

list

Displays a list of packages from a given source. If no sources are specified, all sources defined in %AppData%\NuGet\NuGet.config are used. If NuGet.config specifies no sources, uses the default NuGet feed.

Usage

nuget list [search terms] [options]

Specify optional search terms.

Options

allversions List all versions of a package. By default, only the latest package version is displayed.
configfile (v2.5) Specifies the user specific configuration file. If omitted, nuget.config is used instead.
help Displays help information for the list command.
noninteractive Do not prompt for user input or confirmations.
prerelease Allow prerelease packages to be shown.
source A list of packages sources to search.
verbose Displays a detailed list of information for each package.
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.

Examples

nuget list

nuget list -verbose -allversions

sources

Provides the ability to manage list of sources located in %AppData%\NuGet\NuGet.config or the specified config file.

Usage

nuget sources <List|Add|Remove|Enable|Disable|Update> -Name <name> -Source <source>

Options

configfile (v2.5) Specifies the user specific configuration file. If omitted, %appdata%\NuGet\nuget.config is used instead.
help Displays help information for the sources command.
name Name of the source.
noninteractive Do not prompt for user input or confirmations.
password Password to be used when connecting to an authenticated source.
source Path to the package(s) source.
storepasswordincleartext If present, store the password in unencrypted text instead of the default behavior of storing an encrypted form.
username UserName to be used when connecting to an authenticated source.
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.

spec

Generates a nuspec for a new package. If this command is run in the same folder as a project file (.csproj, .vbproj, .fsproj), it will create a tokenized nuspec file.

Usage

nuget spec [package id]

Options

assemblypath Assembly to use for metadata.
configfile (v2.5) Specifies the user specific configuration file. If omitted, %appdata%\NuGet\nuget.config is used instead.
force Overwrite nuspec file if it exists.
help Displays help information for the spec command.
noninteractive Do not prompt for user input or confirmations.
verbosity Display this amount of details in the output: normal, quiet, (v2.5) detailed.

Examples

nuget spec

nuget spec MyPackage

nuget spec -a MyAssembly.dll

pack

Note: Applies to v2.7+

Creates a NuGet package based on the specified nuspec or project file.

Usage

nuget pack <nuspec | project> [options]

Options

basepath The base path of the files defined in the nuspec file.
build Determines if the project should be built before building the package.
exclude Specifies one or more wildcard patterns to exclude when creating a package.
excludeemptydirectories Prevent inclusion of empty directories when building the package.
help Displays help information for the pack command.
includereferenceprojects Include referenced projects either as dependencies or as part of the package. If a referenced project has a corresponding nuspec file that has the same name as the project, then that referenced project is added as a dependency. Otherwise, the referenced project is added as part of the package.
minclientversion Set the minClientVersion attribute for the created package. This value will override the value of the existing minClientVersion attribute (if any) in the .nuspec file.
msbuildversion Specifies the version of MSBuild to be used with this command. Supported values are 4, 12, 14. By default the MSBuild in your path is picked, otherwise it defaults to the highest installed version of MSBuild.
noninteractive Do not prompt for user input or confirmations.
nodefaultexcludes Prevent default exclusion of NuGet package files and files and folders starting with a dot e.g. .svn.
nopackageanalysis Specify if the command should not run package analysis after building the package.
outputdirectory Specifies the directory for the created NuGet package file. If not specified, the current directory is used.
properties Provides the ability to specify a semicolon ";" delimited list of properties when creating a package.
symbols Determines if a package containing sources and symbols should be created. When specified with a nuspec, creates a regular NuGet package file and the corresponding symbols package.
tool Determines if the output files of the project should be in the tool folder.
verbose Shows verbose output for package building.
verbosity Display this amount of details in the output: normal, quiet, detailed.
version Overrides the version number from the nuspec file.

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 the packages.config file which 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>

When running the nuget pack on this project, the created package will have a dependency on jQuery and microsoft-web-helpers, but will not have a dependency on netfx-Guard.

Examples

nuget pack

nuget pack foo.nuspec

nuget pack foo.csproj

nuget pack foo.csproj -Build -symbols -properties Configuration=Release

# create a package from project foo.csproj, using msbuild version 12 to build the project
nuget pack foo.csproj -Build -symbols -properties Configuration=Release -MSBuildVersion 12

nuget pack foo.nuspec -version 2.1.0

nuget pack foo.nuspec -version 1.0.0 -minclientversion 2.5

push

Pushes a package to the server and publishes it. NuGet's default configuration is obtained by loading %AppData%\NuGet\NuGet.config, then loading any nuget.config or .nuget\nuget.config starting from root of drive and ending in current directory.

Usage

nuget push <package path> [API key] [options]

Specify the path to the package and your API key to push the package to the server.

Options

apikey The API key for the server.
configfile (v2.5) Specifies the user specific configuration file. If omitted, nuget.config is used instead.
help Displays help information for the push command.
noninteractive Do not prompt for user input or confirmations.
source Specifies the server URL. Starting with NuGet 3.4.2, this is a mandatory parameter unless the NuGet.config file specifies a DefaultPushSource value.
Starting with NuGet 2.5, if nuget.exe identifies a UNC/folder source, it will copy the file to the source.
timeout Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes).
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.

Examples

Starting with NuGet 3.4.2, -Source is a mandatory parameter unless DefaultPushSource config value is set in the NuGet config file.
nuget push foo.nupkg 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a -Source https://www.nuget.org/api/v2/package

nuget push foo.nupkg 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a

nuget push foo.nupkg 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a -s https://customsource/

nuget push foo.nupkg

nuget push foo.symbols.nupkg

nuget push foo.nupkg -Timeout 360

nuget push *.nupkg

Starting with NuGet 2.5 push supports a UNC/Folder source
nuget.exe push -source \\mycompany\repo\ mypackage.1.0.0.nupkg

setapikey

Saves an API key for a given server URL. When no URL is provided API key is saved for the NuGet gallery.

Usage

nuget setapikey <API key> [options]

Options

configfile (v2.5) The NuGet configuration file. If not specified, file %AppData%\NuGet\NuGet.config is used as configuration file.
help Displays help information for the setapikey command.
noninteractive Do not prompt for user input or confirmations.
source Server URL where the API key is valid.
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.

Examples

nuget setapikey 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a

nuget setapikey 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a -source https://example.com/nugetfeed

init

(v3.3) Adds all the packages from a flat folder of nupkgs to the destination package source in a hierarchical layout as described below. When restoring or updating against your package source, this layout has significant performance benefits. For this command, both the source package source and the destination package source must be a folder or a UNC share. In order to expand all the files in the package to the destination package source, use the -expand switch.

\\destinationpackagesource\
    yourpackage\
        0.0.1-beta\
            yourpackage.0.0.1-beta.nupkg
            yourpackage.nuspec
            yourpackage.0.0.1-beta.nupkg.sha512

Usage

nuget init <srcPackageSourcePath> <destPackageSourcePath> options]

Options

expand If provided, all the files in the package(s) are added to destination package source.
help Displays help information for the init command.
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.

Examples

nuget init c:\foo c:\bar

nuget init \\foo\packages \\bar\packages

add

Note: Applies to v3.3+

Adds a specified package to your package source in a hierarchical layout as described below. When restoring or updating against your package source, this layout has significant performance benefits. For this command, your package source must be a folder or a UNC share. In order to expand all the files in the package to the destination package source, use the -expand switch.

\\yourpackagesource\
    yourpackage\
        0.0.1-beta\
            yourpackage.0.0.1-beta.nupkg
            yourpackage.nuspec
            yourpackage.0.0.1-beta.nupkg.sha512

Usage

nuget add <packagePath> -Source <folderBasedPackageSource> [options]
Note:
Http sources are not supported.

Options

expand If provided, all the files in the package are added to your package source.
help Displays help information for the add command.
source Specifies the folderBasedPackageSource to which the nupkg will be added. Http sources are not supported.
verbosity Specifies the amount of details displayed in the output: normal, quiet, detailed.

Examples

nuget add foo.nupkg -source c:\bar\

nuget add foo.nupkg -source \\bar\packages\

config

Gets or sets NuGet config values.

Usage

nuget config -set name=value

Options

configfile The NuGet configuration file. If not specified, file %AppData%\NuGet\NuGet.config is used as configuration file.
help Displays help information for the config command.
noninteractive Do not prompt for user input or confirmations.
set One or more key-value pairs to be set in the configuration.
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.

Examples

nuget config -set HTTP_PROXY=http://127.0.0.1 -set HTTP_PROXY.USER=domain\user

locals

Note: Applies to v3.3+

Clears or lists local NuGet resources such as http request cache, packages cache, or machine-wide global packages folder.

nuget locals <target> -clear

Where <target> is one of the following options: all, http-cache, packages-cache, global-packages, (v3.4) temp.

Options

clear Clear the resources in the specified cache location.
help Displays help information for the config command.
list List the resources of the cache locations.
verbosity Specifies the amount of details displayed in the output: normal, quiet, detailed.

mirror

Mirrors a package and its dependencies from the specified source repositories to the target repository.

Note: Deprecated from v3.2+
To enable this command for versions of NuGet before v3.2, navigate to https://nuget.codeplex.com/releases, select newest stable release, download NuGet.ServerExtensions.dll and Nuget-Signed.exe to your local disk and rename the Nuget-Signed.Exe to nuget.exe..

Usage

nuget mirror <packageId|pathToPackagesConfig> <listUrlTarget> <publishUrlTarget> [options]

Specify the id of the package to mirror, the url to query the target repository (list ) and the url to push packages to the target repository. If a path to a packages.config file is used instead of a package id, all the packages it contains are mirrored to the given version (if specified) or latest otherwise.

Assuming you're targeting a private repository under https://machine/repo installed using NuGet.Server, the list and push urls will be https://machine/repo/nuget and https://machine/repo/api/v2/package respectively.

Options

apikey The API key for pushing to the target repository. If not specified, the one specified in %AppData%\NuGet\NuGet.config is used.
help Displays help information for the mirror command.
nocache Disables the default behavior of using a local cache when a package or a package dependency is not found in the specified sources. Instead, only the specified sources will be used.
noop Log what would be done without actually doing it. Assumes success for push operations.
prerelease When set, prereleased packages will be mirrored.
source A list of package sources to mirror. If no sources are specified, the ones defined in %AppData%\NuGet\NuGet.config are used. If the default NuGet config file specifies no sources, the default NuGet feed will be used.
timeout Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes).
version The version of the package to install. If not specified, latest version is mirrored.

Examples

nuget mirror packages.config  https://MyRepo/nuget https://MyRepo/api/v2/package -source https://nuget.org/api/v2 -apikey myApiKey -NoCache

nuget mirror Microsoft.AspNet.Mvc https://MyRepo/nuget https://MyRepo/api/v2/package -version 4.0.20505.0

nuget mirror Microsoft.Net.Http https://MyRepo/nuget https://MyRepo/api/v2/package -prerelease

help

Displays general help information and help information about other commands.

Usage

nuget help [command]

Pass a command name to display help information for that command.

Options

all Print detailed help for all available commands.
help Displays help information for the help command.
markdown Print detailed all help in markdown format.
noninteractive Do not prompt for user input or confirmations.
verbosity Specifies the amount of details displayed in the output: normal, quiet, (v2.5) detailed.

Examples

nuget help

nuget help push

nuget ?

nuget push -?