(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

    指定封裝安裝之後要儲存的檔案類型:、或的其中一個 nuspec nupkg nuspec;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