(NuGet CLI 安装命令) install command (NuGet CLI)

适用于: 包使用 • 受支持的版本: 全部Applies to: package consumption • Supported versions: all

使用指定的包源,将包下载并安装到项目中,默认为当前文件夹。Downloads and installs a package into a project, defaulting to the current folder, using specified package sources.


若要直接在项目上下文之外下载包,请访问 nuget.org 上的包页面,并选择 " 下载 " 链接。To download a package directly outside the context of a project, visit the package's page on nuget.org and select the Download link.

如果未指定源,则 %appdata%\NuGet\NuGet.Config 使用 (Windows) 或 ~/.nuget/NuGet/NuGet.Config (Mac/Linux) 中列出的全局配置文件中列出的源。If no sources are specified, those listed in the global configuration file, %appdata%\NuGet\NuGet.Config (Windows) or ~/.nuget/NuGet/NuGet.Config (Mac/Linux), are used. 有关更多详细信息,请参阅 常见 NuGet 配置See Common NuGet configurations for additional details.

如果未指定特定包,将 install 安装项目文件中列出的所有程序包 packages.config ,使其类似于 restoreIf no specific packages are specified, install installs all packages listed in the project's packages.config file, making it similar to restore.

install此命令不会修改项目文件,也不会修改项目文件, packages.config 这类似于 restore ,因为它仅将包添加到磁盘,但不会更改项目的依赖项。The install command does not modify a project file or packages.config; in this way it's similar to restore in that it only adds packages to disk but does not change a project's dependencies.

若要添加依赖项,请在 Visual Studio 中通过包管理器 UI 或控制台添加包,或修改 packages.config ,然后运行 installrestoreTo add a dependency, either add a package through the Package Manager UI or Console in Visual Studio, or modify packages.config and then run either install or restore.


nuget install <packageID | configFilePath> [options]

其中 <packageID> ,使用最新) 版本将包命名为要安装 (,或 <configFilePath> 标识 packages.config 列出要安装的包的文件。where <packageID> names the package to install (using the latest version), or <configFilePath> identifies the packages.config file that lists the packages to install. 可以使用选项指示特定版本 -VersionYou can indicate a specific version with the -Version option.


  • -ConfigFile

    要应用的 NuGet 配置文件。The NuGet configuration file to apply. 如果未指定,则 %AppData%\NuGet\NuGet.Config 使用 (Windows) ~/.nuget/NuGet/NuGet.Config~/.config/NuGet/NuGet.Config (Mac/Linux) 。If not specified, %AppData%\NuGet\NuGet.Config (Windows), or ~/.nuget/NuGet/NuGet.Config or ~/.config/NuGet/NuGet.Config (Mac/Linux) is used.

  • -DependencyVersion

    * (4.4 +) * 要使用的依赖项包的版本,可以是下列项之一:(4.4+) The version of the dependency packages to use, which can be one of the following:

    • 最低 (默认) :最低版本Lowest (default): the lowest version
    • HighestPatch:最小主要、次要和最高修补程序的版本HighestPatch: the version with the lowest major, lowest minor, highest patch
    • HighestMinor:最小主要版本号最高的版本,最高修补程序HighestMinor: the version with the lowest major, highest minor, highest patch
    • 最高:最高版本Highest: the highest version
    • 忽略:将不使用任何依赖项包Ignore: No dependency packages will be used

  • -DirectDownload

    直接下载,无需填充元数据或二进制文件的任何缓存。Download directly without populating any caches with metadata or binaries.

  • -DisableParallelProcessing

    禁止并行安装多个包。Disables installing multiple packages in parallel.

  • -x|-ExcludeVersion

    将包安装到仅带有包名称而不是版本号的名为的文件夹中。Installs the package to a folder named with only the package name and not the version number.

  • -FallbackSource

    * (3.2 +) * 在主或默认源中找不到包时要用作回退的包的列表。(3.2+) A list of package sources to use as fallbacks in case the package isn't found in the primary or default source.

  • -ForceEnglishOutput

    * (3.5 +) * 使用固定的、基于英语的区域性强制运行 nuget.exe。(3.5+) Forces nuget.exe to run using an invariant, English-based culture.

  • -Framework

    * (4.4 +) * 用于选择依赖项的目标框架。(4.4+) Target framework used for selecting dependencies. 如果未指定,默认值为 "Any"。Defaults to 'Any' if not specified.

  • -?|-help

    显示命令的帮助信息。Displays help information for the command.

  • -NoCache

    阻止 NuGet 使用缓存的包。Prevents NuGet from using cached packages. 请参阅 管理全局包和缓存文件夹See Managing the global packages and cache folders.

  • -NonInteractive

    禁止提示用户输入或确认。Suppresses prompts for user input or confirmations.

  • -OutputDirectory

    指定在其中安装包的文件夹。Specifies the folder in which packages are installed. 如果未指定文件夹,则使用当前文件夹。If no folder is specified, the current folder is used.

  • -PackageSaveMode

    指定包安装后要保存的文件类型: nuspecnupkgnuspec;nupkgSpecifies the types of files to save after package installation: one of nuspec, nupkg, or nuspec;nupkg.

  • -PreRelease

    允许安装预发行程序包。Allows prerelease packages to be installed. 当还原包时,不需要此标志 packages.configThis flag is not required when restoring packages with packages.config.

  • -RequireConsent

    验证在下载和安装包之前是否启用了还原包。Verifies that restoring packages is enabled before downloading and installing the packages. 有关详细信息,请参阅 包还原For details, see Package Restore.

  • -SolutionDirectory

    指定要为其还原包的解决方案的根文件夹。Specifies root folder of the solution for which to restore packages.

  • -Source

    指定要使用的 Url) (包的列表。Specifies the list of package sources (as URLs) to use. 如果省略,则该命令使用配置文件中提供的源,请参阅 常见的 NuGet 配置If omitted, the command uses the sources provided in configuration files, see Common NuGet configurations.

  • -Verbosity [normal|quiet|detailed]

    指定在输出中显示的详细信息的数量: normal (默认) 、 quietdetailedSpecifies the amount of detail displayed in the output: normal (the default), quiet, or detailed.

  • -Version

    指定要安装的程序包的版本。Specifies the version of the package to install.

另请参阅 环境变量Also see Environment variables


nuget install elmah

nuget install packages.config

nuget install ninject -OutputDirectory c:\proj