安裝 NuGet 用戶端工具Install NuGet client tools

想要安裝套件?請參閱安裝 NuGet 套件的方式Looking to install a package? See Ways to install NuGet packages.

若要以套件取用者或建立者身分使用 NuGet,您可以使用命令列介面 (CLI) 工具以及 Visual Studio 中的 NuGet 功能。To work with NuGet, as a package consumer or creator, you can use command-line interface (CLI) tools as well as NuGet features in Visual Studio. 本文簡要概述不同工具的功能、安裝它們的方式,以及它們相對的功能可用性This article briefly outlines the capabilities of the different tools, how to install them, and their comparative feature availability. 若要開始使用 NuGet 來取用套件,請參閱安裝並使用套件 (.NET CLI)安裝並使用套件 (Visual Studio)To get started using NuGet to consume packages, see Install and use a package (.NET CLI) and Install and use a package (Visual Studio). 若要開始建立 NuGet 套件,請參閱建立及發佈 .NET Standard 套件 (dotnet CLI)建立及發佈 .NET Standard 套件 (Visual Studio)To get started creating NuGet packages, see Create and publish a NET Standard package (dotnet CLI) and Create and publish a NET Standard package (Visual Studio).

工具               Tool                說明Description 下載         Download         
dotnet.exedotnet.exe 適用於 .NET Core 與 .NET Standard 程式庫,以及適用於以 .NET Framework 為目標等 SDK 樣式專案的 CLI 工具 (請參閱 SDK 屬性)。CLI tool for .NET Core and .NET Standard libraries, and for any SDK-style project such as one that targets .NET Framework (see SDK attribute). 隨附於 .NET Core SDK,並提供所有平台上的核心 NuGet 功能。Included with the .NET Core SDK and provides core NuGet features on all platforms. .NET Core SDK.NET Core SDK
nuget.exenuget.exe 適用於 .NET Framework 程式庫以及適用於以 .NET Standard 程式庫為目標的非 SDK 樣式專案 CLI 工具。CLI tool for .NET Framework libraries and for non-SDK-style projects that target .NET Standard libraries. 在 Windows 上提供所有的 NuGet 功能,於 Mono 執行時在 Mac 和 Linux 上提供大部分功能。Provides all NuGet capabilities on Windows, provides most features on Mac and Linux when running under Mono. nuget.exenuget.exe
Visual StudioVisual Studio 在 Windows 上,透過套件管理員 UI 和套件管理員主控台提供 NuGet 功能;隨附 .NET 相關的工作負載。On Windows, provides NuGet capabilities through the Package Manager UI and Package Manager Console; included with .NET-related workloads. 在 Mac 上,透過 UI 提供特定功能。On Mac, provides certain features through the UI. 在 Visual Studio Code 中,會透過延伸模組來提供 NuGet 功能。In Visual Studio Code, NuGet features are provided through extensions. Visual Studio 2017Visual Studio 2017

MSBuild CLI 也提供還原和建立套件的能力,這主要用於組建伺服器。The MSBuild CLI also provides the ability to restore and create packages, which is primarily useful on build servers. MSBuild 並非適合用來搭配 NuGet 使用的一般用途工具。MSBuild is not a general-purpose tool for working with NuGet.

CLI 工具CLI tools

這兩個 NuGet CLI 工具是 dotnet.exenuget.exeThe two NuGet CLI tools are dotnet.exe and nuget.exe. 請參閱功能可用性以進行比較。See feature availability for a comparison.

  • 若要以 .NET Core 或 .NET Standard 為目標,請使用 dotnet CLI。To target .NET Core or .NET Standard, use the dotnet CLI. SDK 樣式的專案格式需要 dotnet CLI,該格式使用 SDK 屬性The dotnet CLI is required for the SDK-style project format, which uses the SDK attribute.
  • 若以 .NET Framework 為目標 (限非 SDK 樣式專案),請使用 nuget.exe CLITo target .NET Framework (non-SDK-style project only), use the nuget.exe CLI. 專案若已移轉至 packages.config,請使用 dotnet CLI。If the project is migrated to packages.config, use the dotnet CLI.

dotnet.exe CLIdotnet.exe CLI

.NET Core 2.0 CLI dotnet.exe 適用於所有平台 (Windows、Mac 和 Linux),並提供核心 NuGet 功能,例如安裝、還原和發行套件。The .NET Core 2.0 CLI, dotnet.exe, works on all platforms (Windows, Mac, and Linux) and provides core NuGet features such as installing, restoring, and publishing packages. dotnet 提供與 .NET Core 專案檔 (例如 .csproj) 的直接整合,這在大多數案例中很有幫助。dotnet provides direct integration with .NET Core project files (such as .csproj), which is helpful in most scenarios. dotnet 也會針對每個平台直接建置,而且不會要求您安裝 Mono。dotnet is also built directly for each platform and does not require you to install Mono.

安裝:Installation:

若要了解如何使用 dotnet CLI 的基本命令,請參閱使用 dotnet CLI 安裝和使用套件To learn how to use basic commands with the dotnet CLI, see Install and use packages using the dotnet CLI.

nuget.exe CLInuget.exe CLI

nuget.exe CLI (nuget.exe) 是適用於 Windows 的命令列公用程式,它提供所有 NuGet 功能,也可以在 Mac OSX 與 Linux 上使用 Mono 來執行,但有一些限制。The nuget.exe CLI, nuget.exe, is the command-line utility for Windows that provides all NuGet capabilities; it can also be run on Mac OSX and Linux using Mono with some limitations.

安裝:Installation:

WindowsWindows

注意

NuGet.exe 5.0 及更新版本需要.NET Framework 4.7.2 或更新版本才能執行。NuGet.exe 5.0 and later require .NET Framework 4.7.2 or later to execute.

  1. 請瀏覽 nuget.org/downloads 並選取 NuGet 3.3 或更高版本 (2.8.6 與 Mono 不相容)。Visit nuget.org/downloads and select NuGet 3.3 or higher (2.8.6 is not compatible with Mono). 一律建議使用最新版本,需要 4.1.0 以上版本才能將套件發行至 nuget.org。The latest version is always recommended, and 4.1.0+ is required to publish packages to nuget.org.
  2. 每個下載項目直接是 nuget.exe 檔案。Each download is the nuget.exe file directly. 指示您的瀏覽器將檔案儲存到您選擇的資料夾。Instruct your browser to save the file to a folder of your choice. 該檔案不是安裝程式;如果直接從瀏覽器執行,您將不會看到任何項目。The file is not an installer; you won't see anything if you run it directly from the browser.
  3. 將放置 nuget.exe 的資料夾新增至您的 PATH 環境變數中,以便從任何地方使用 CLI 工具。Add the folder where you placed nuget.exe to your PATH environment variable to use the CLI tool from anywhere.

macOS/LinuxmacOS/Linux

行為可能會隨作業系統發佈而稍微不同。Behaviors may vary slightly by OS distribution.

  1. 安裝 Mono 4.4.2 或更新版本Install Mono 4.4.2 or later.

  2. 在殼層提示字元中執行下列命令:Execute the following command at a shell prompt:

    # Download the latest stable `nuget.exe` to `/usr/local/bin`
    sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
    
  3. 將下列指令碼加入到適用於您的作業系統的檔案 (通常為 ~/.bash_aliases~/.bash_profile) 來建立別名:Create an alias by adding the following script to the appropriate file for your OS (typically ~/.bash_aliases or ~/.bash_profile):

    # Create as alias for nuget
    alias nuget="mono /usr/local/bin/nuget.exe"
    
  4. 重新載入殼層。Reload the shell. 輸入 nuget (不含任何參數) 來測試安裝。Test the installation by entering nuget with no parameters. NuGet CLI 說明應該會顯示。NuGet CLI help should display.

提示

在 Windows 上使用 nuget update -self,將現有的 nuget.exe 更新為最新版本。Use nuget update -self on Windows to update an existing nuget.exe to the latest version.

若要了解如何使用 nuget.exe CLI 的基本命令,請參閱使用 nuget.exe CLI 安裝和使用套件To learn how to use basic commands with the nuget.exe CLI, see Install and use packages using the nuget.exe CLI.

注意

最新建議的 NuGet CLI 一律可在 https://dist.nuget.org/win-x86-commandline/latest/nuget.exe 找到。The latest recommended NuGet CLI is always available at https://dist.nuget.org/win-x86-commandline/latest/nuget.exe. 為了與舊版持續整合系統相容,先前的 URL https://nuget.org/nuget.exe 目前會提供已被取代的 2.8.6 CLI 工具For compatibility purposes with older continuous integration systems, a previous URL, https://nuget.org/nuget.exe currently provides the deprecated 2.8.6 CLI tool.

Visual StudioVisual Studio

  • Visual Studio Code:NuGet 功能可透過市集擴充功能取得,或者使用 dotnet.exenuget.exe CLI 工具來取得。Visual Studio Code: NuGet capabilities are available through marketplace extensions, or use the dotnet.exe or nuget.exe CLI tools.

  • Visual Studio for Mac:已直接內建特定的 NuGet 功能。Visual Studio for Mac: certain NuGet capabilities are built in directly. 如需逐步解說,請參閱在專案中包含 NuGet 套件See Including a NuGet package in your project for a walkthrough. 針對其他功能,請使用 dotnet.exenuget.exe CLI 工具。For other capabilities, use the dotnet.exe or nuget.exe CLI tools.

  • Windows 上的 Visual Studio:NuGet 套件管理員隨附於 Visual Studio 2012 與更新版本。Visual Studio on Windows: The NuGet Package Manager is included with Visual Studio 2012 and later. Visual Studio 提供套件管理員 UI套件管理員主控台,您可以透過它們執行大部分 NuGet 作業。Visual Studio provides the Package Manager UI and the Package Manager Console, through which you can run most NuGet operations.

    • 在 Visual Studio 2017 中啟動,此安裝程式包含 NuGet 套件管理員以及採用 .NET 的任何工作負載。Starting in Visual Studio 2017, the installer includes the NuGet Package Manager with any workload that employs .NET. 若要個別安裝或驗證已安裝套件管理員,請執行 Visual Studio 安裝程式,並核取 [個別元件] > [程式碼工具] > [NuGet 套件管理員] 下的選項。To install separately, or to verify that the Package Manager is installed, run the Visual Studio installer and check the option under Individual Components > Code tools > NuGet package manager.
    • 套件管理員 UI 和主控台對 Windows 上的 Visual Studio 而言是不同的。The Package Manager UI and Console are unique to Visual Studio on Windows. 它們目前無法供 Visual Studio for Mac 使用。They are not presently available on Visual Studio for Mac.
    • 需要 CLI 工具,以支援 IDE 中的 NuGet 功能。A CLI tool is required to support NuGet features in the IDE. 您可以使用 dotnet CLI 或 nuget.exe CLI。You can use either the dotnet CLI or the the nuget.exe CLI. dotnet CLI 會隨一些 Visual Studio 工作負載一起安裝,例如 .NET Core。The dotnet CLI is installed with some Visual Studio workloads, such as .NET Core. nuget.exe CLI 必須單獨安裝,如先前所述。The nuget.exe CLI must be installed separately as described earlier.
    • 套件管理員主控台命令只能在 Windows 上的 Visual Studio 內運作,無法在其他 PowerShell 環境中運作。Package Manager Console commands work only within Visual Studio on Windows and do not work within other PowerShell environments.
    • 針對 Visual Studio 2010 及更早版本,安裝「適用於 Visual Studio 的 NuGet 套件管理員」擴充功能。For Visual Studio 2010 and earlier, install the "NuGet Package Manager for Visual Studio" extension.
    • 您也可以從 https://dist.nuget.org/index.html 下載適用於 Visual Studio 2013 和 2015 的 NuGet 延伸模組。NuGet Extensions for Visual Studio 2013 and 2015 can also be downloaded from https://dist.nuget.org/index.html.
    • 如果您想要預覽即將推出的 NuGet 功能,請安裝 Visual Studio 2017 Preview,它能與穩定版本的 Visual Studio 並存運作。If you'd like to preview upcoming NuGet features, install the Visual Studio 2017 Preview, which works side-by-side with stable releases of Visual Studio. 若要針對預覽回報問題或分享想法,請在 NuGet GitHub 存放庫 (英文) 上建立問題。To report problems or share ideas for previews, open an issue on the NuGet GitHub repository.

功能可用性Feature availability

功能Feature dotnet CLIdotnet CLI nuget CLI (Windows)nuget CLI (Windows) nuget CLI (Mono)nuget CLI (Mono) Visual Studio (Windows)Visual Studio (Windows) Visual Studio for MacVisual Studio for Mac
搜尋套件Search packages
安裝/解除安裝套件Install/uninstall packages ✔(1)✔(1)
更新套件Update packages
還原套件Restore packages ✔(2)✔(2)
管理套件摘要 (來源)Manage package feeds (sources)
管理摘要上的套件Manage packages on a feed
設定摘要的 API 金鑰Set API keys for feeds
建立套件(3)Create packages(3) ✔(4)✔(4)
發行套件Publish packages
複製套件Replicate packages
管理 global-package 和快取資料夾Manage global-package and cache folders
管理 NuGet 組態Manage NuGet configuration

(1) 不會影響專案檔;請改為使用 dotnet.exe(1) Does not affect project files; use dotnet.exe instead.

(2) 只能搭配 packages.config 檔案運作,無法搭配方案 (.sln) 檔案運作。(2) Works only with packages.config file and not with solution (.sln) files.

(3) 各種進階的套件功能只能透過 CLI 取得,因為這些功能不會在 Visual Studio UI 工具中呈現。(3) Various advanced package features are available through the CLI only as they aren't represented in the Visual Studio UI tools.

(4) 可搭配 .nuspec 檔案運作,但無法搭配專案檔運作。(4) Works with .nuspec files but not with project files.

在 Windows 上工作的開發人員也可以探索 NuGet 套件總管 (英文),這是一個開放原始碼的獨立工具,可讓您以視覺化方式瀏覽、建立和編輯 NuGet 套件。Developers working on Windows can also explore the NuGet Package Explorer, an open-source, stand-alone tool to visually explore, create, and edit NuGet packages. 例如,它非常適合用來對套件結構進行實驗性變更,而不需重建套件。It's very helpful, for example, to make experimental changes to a package structure without rebuilding the package.