NuGet Command-Line Reference
In previous chapters, you’ve seen the NuGet command line being used. While we’ve covered most commands, this appendix lists all available commands from the NuGet command line. Parts of this appendix are based on the information available on the official NuGet web site at http://docs.nuget.org/docs/reference/command-line-reference. NuGet documentation (from the Outercurve Foundation) is licensed under Creative Commons license BY 3.0 (http://creativecommons.org/licenses/by/3.0/). Commands in this chapter are listed alphabetically.
This command displays general help information and help information about other commands:
nuget help [command]
For example, retrieving help for the NuGet push command may be done by issuing the following command:
nuget help push
Available options are shown in Table B-1.
Table B-1. Available Options for the NuGet help Command
Option | Description |
---|---|
All | Print detailed information for all available commands. |
Markdown | Print detailed help in markdown format. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
The NuGet config command can be used to set values in a NuGet configuration file. More on configuration files can be found in Appendix D. Here’s an example:
nuget config -Set <name>=<value>
Available options are shown in Table B-2.
Table B-2. Available Options for the NuGet config Command
Option | Description |
---|---|
Set | One or more key-value pairs to be set in config. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
After publishing a package to a NuGet feed, the NuGet delete command enables a user to delete a package from the server. Note that some NuGet feeds, like the official NuGet Gallery at NuGet.org, may not allow package deletion. The reason for this is threefold:
Here’s an example:
nuget delete <package Id> <package version> [API Key] [options]
Available options are shown in Table B-3.
Table B-3. Available Options for the NuGet delete Command
Option | Description |
---|---|
Source | Specify the server URL. |
NoPrompt | Do not prompt when deleting. |
ApiKey | The API key used to connect to the server. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
The following command installs a package by using the specified sources:
nuget install packageId|pathToPackagesConfig [options]
If no sources are specified, all sources defined in %AppData%NuGetNuGet.config are used. If nuget.config specifies no sources, the default NuGet feed is used.
Note that when no package name is specified to the install command and instead packages.config is referenced, the install command will install all packages listed in packages.config. This may be very useful to restore a set of dependencies in a project without having to explicitly install all packages manually.
Available options are shown in Table B-4.
Table B-4. Available Options for the NuGet install Command
Option | Description |
---|---|
Source | Specify the server URL. |
OutputDirectory | Specify the directory in which packages will be installed. |
Version | The version of the package to install. |
ExcludeVersion | If set, the destination folder will contain only the package name, not the version number. |
PreRelease | Allow prerelease packages to be installed. This flag is not required when restoring packages from packages.config. |
NoCache | When NoCache = true, NuGet contacts the configured package source to check for the existence of the requested package. When it has found the version, it will use the version from the cache if it’s there or download a fresh copy if it’s not. If the version no longer exists in the feed, the version from the cache is ignored. |
RequireConsent | Checks whether package restore is granted before installing a package. |
SolutionDirectory | Solution directory root used for package restore. |
FileConflictAction | The action to take, when asked to overwrite or ignore existing files referenced by the project. Possible values: Overwrite, Ignore, None. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
The following command displays a list of packages from a given source:
nuget list [search terms] [options]
If no package sources are specified, all sources defined in %AppData%NuGetNuGet.config are used. If nuget.config specifies no sources, the default NuGet feed is used.
Available options are shown in Table B-5.
Table B-5. Available Options for the NuGet list Command
Option | Description |
---|---|
Source | A list of package sources in which to search. |
Verbose | Display detailed information for each package. |
AllVersions | List all versions of a package. By default, only the last version is displayed. |
PreRelease | Allow prerelease packages to be listed. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
Create a NuGet package based on the specified .nuspec file, a project file, or an assembly name by using the pack command:
nuget pack <nuspec | project | assembly> [options]
Available options are shown in Table B-6.
Table B-6. Available Options for the NuGet pack Command
Option | Description |
---|---|
OutputDirectory | Specify the directory for the created NuGet package file. If none is specified, use the current directory. |
BasePath | The base path of the files defined in the .nuspec file. |
Verbose | Show verbose output for package building. |
Version | Override the version number from the .nuspec file. |
Exclude | Specify one or more wildcard patterns to exclude when creating a package. |
Symbols | Determine whether a package containing sources and symbols should be created. When specified with a .nuspec file, create a regular NuGet package file and the corresponding symbols package. |
Tool | Determine whether the output files of the project should be in the tools folder. |
Build | Determine whether the project should be built before building the package. |
NoDefaultExcludes | Prevent default exclusion of NuGet package files and files and folders starting with a dot (for example, .svn). |
NoPackageAnalysis | Specify whether the command should not run package analysis after building the package. |
IncludeReferencedProjects | 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, that referenced project is added as a dependency. Otherwise, the referenced project is added as part of the package. |
ExcludeEmptyDirectories | Prevent inclusion of empty directories when building the package. |
Properties | Provide the ability to specify a semicolon-delimited list of properties when creating a 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. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
The following command pushes a package to the server:
nuget push <package path> [API key] [options]
Depending on the NuGet feed you are pushing to, the package will immediately be published as well. Optionally, this behavior can be disabled by specifying the -CreateOnly option.
Available options are shown in Table B-7.
Table B-7. Available Options for the NuGet push Command
Option | Description |
---|---|
Source | The package source to publish to. By default, NuGet assumes you are pushing to a v2 feed and appends /api/v2/package to the specified package source URL. To overcome this or to push to a v1 feed, you have to explicitly specify the source URL. If omitted, NuGet.org will be used unless a DefaultPushSource configuration value is specified. |
ApiKey | The API key for the server. |
Timeout | Specifies the timeout for pushing to the server in seconds. Defaults to 300 seconds (5 minutes). |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file, and then any nuget.config or .nuget uget.config starting from the root of the drive and ending in the current directory. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
The restore Command (NuGet >2.7)
The following command restores NuGet packages for a solution file or packages.config file specified. Note that it is available only in NuGet version 2.7 and newer.
nuget restore [solution | packages.config file] [options]
If a solution is specified, this command restores NuGet packages that are installed in the solution and in projects contained in the solution. Otherwise, the command restores packages listed in the specified packages.config file.
If no package sources are specified, all sources defined in %AppData%NuGetNuGet.config are used. If NuGet.config specifies no sources, the default NuGet feed is used.
Available options are shown in Table B-8.
Table B-8. Available Options for the NuGet install Command
Option | Description |
---|---|
Source | A list of package sources to use. |
NoCache | If set, the NuGet package cache will not be used for restoring packages. |
RequireConsent | Checks whether package restore is granted before installing a package. |
DisableParallelProcessing | If set, parallel NuGet package restores are disabled. |
PackagesDirectory (or OutputDirectory) | Specify the directory in which packages will be restored. |
SolutionDirectory | Solution directory root used for package restore. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
This command saves an API key for a given server URL:
nuget setapikey <API key> [options]
When no URL is provided, the API key for the official NuGet gallery is saved. API keys are stored in %AppData%NuGetNuGet.config.
Available options are shown in Table B-9.
Table B-9. Available Options for the NuGet setapikey Command
Option | Description |
---|---|
Source | The package source to store the API key for. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
This command provides the ability to manage list of sources located in %AppData%NuGetNuGet.config:
nuget sources <List|Add|Remove|Enable|Disable> -Name [name] -Source [source]
Available options are shown in Table B-10.
Table B-10. Available Options for the NuGet sources Command
Option | Description |
---|---|
Name | Name of the source. |
Source | Path to the package source. |
Username | The username to be used when connecting to a server that requires authentication. |
Password | The password to be used when connecting to a server that requires authentication. |
StorePasswordInClearText | Do not encrypt the password when storing it in the configuration file. Note that by default, passwords will be encrypted with the computer’s machineKey. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
Generate a .nuspec for a new package with the following command:
nuget spec [package id]
If this command is run in the same folder as a project file (.csproj, .vbproj, or .fsproj), it will create a package manifest that uses replacement tokens, such as $id$, $version$, $description$, and $authors$.
Available options are shown in Table B-11.
Table B-11. Available Options for the NuGet spec Command
Option | Description |
---|---|
AssemblyPath | Assembly to use for metadata. |
Force | Overwrite a .nuspec file if it exists. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
Update packages to latest available versions by using the following command, which also updates nuget.exe itself.
nuget update <packages.config|solution>
Available options are shown in Table B-12.
Table B-12. Available Options for the NuGet update Command
Option | Description |
---|---|
Source | A list of package sources to search for updates. |
Id | Package IDs to update. |
RepositoryPath | Path to the local packages’ folder (location where packages are installed). |
Safe | Looks for updates with the highest version available within the same major and minor version as the installed package. |
Self | Update the running nuget.exe file to the newest version available from the server. |
Verbose | Show verbose output while updating. |
Prerelease | Allow updating to prerelease versions. This flag is not required when updating prerelease packages that are already installed. |
FileConflictAction | The action to take, when asked to overwrite or ignore existing files referenced by the project. Possible values: Overwrite, Ignore, None. |
ConfigFile | The NuGet configuration file to use. If not specified, %AppData%NuGetNuGet.config is used as the configuration file. |
Verbosity | Specifies the amount of detail in the output. Possible values are normal, quiet, detailed. |
NonInteractive | Do not prompt for user input or confirmations. |
Help | Help information for the command. |
18.118.2.225