PowerShell 參考PowerShell reference

套件管理員主控台會在 Windows Visual Studio 內提供 PowerShell 介面,以透過下列特定命令與 NuGet 互動。The Package Manager Console provides a PowerShell interface within Visual Studio on Windows to interact with NuGet through the specific commands listed below. (目前無法在 Visual Studio for Mac 中使用主控台)。如需使用主控台的指南,請參閱使用套件管理員主控台安裝和管理套件主題。(The console is not presently available in Visual Studio for Mac.) For a guide to using the console, see Install and manage packages using Package Manager Console topic.


所有 PowerShell 命令都只與套件耗用量相關。All PowerShell commands relate only to package consumption. 除了封裝也可以是其他套件取用者的範圍之外,沒有任何 PowerShell 命令與建立和發行封裝有關。No PowerShell commands relate to creating and publishing packages except to the extent that a package can also be a consumer of other packages.


此處所列的命令是 Visual Studio 中的套件管理員主控台所特有,而且與一般 PowerShell 環境中可用的套件管理模組命令不同。The commands listed here are specific to the Package Manager Console in Visual Studio, and differ from the Package Management module commands that are available in a general PowerShell environment. 具體而言,每個環境都有其他無法使用的命令,而且具有相同名稱的命令在其特定引數中也可能不同。Specifically, each environment has commands that are not available in the other, and commands with the same name may also differ in their specific arguments. 在 Visual Studio 中使用套件管理主控台時,會套用此目前主題中記載的命令和引數。When using the Package Management Console in Visual Studio, the commands and arguments documented in this present topic apply.

一般命令Common Commands 描述Description NuGet 版本NuGet Version
Install-PackageInstall-Package 將封裝及其相依性安裝到專案中。Installs a package and its dependencies into the project. 全部All
Update-PackageUpdate-Package 更新封裝及其相依性,或專案中的所有封裝。Updates a package and its dependencies, or all packages in a project. 全部All
Find-PackageFind-Package 使用套件識別碼或關鍵字搜尋封裝來源。Searches a package source using a package ID or keywords. 3.0+3.0+
Get-PackageGet-Package 抓取本機存放庫中安裝的封裝清單,或列出可從封裝來源取得的套件。Retrieves the list of packages installed in the local repository, or lists packages available from a package source. 全部All
次要命令Secondary Commands 描述Description NuGet 版本NuGet Version
Add-BindingRedirectAdd-BindingRedirect 檢查項目輸出路徑中的所有元件,並在必要時將系結重新導向新增至 app.configweb.configExamines all assemblies within the output path for a project and adds binding redirects to the app.config or web.config where necessary. 全部All
Get-ProjectGet-Project 顯示預設或指定專案的相關資訊。Displays information about the default or specified project. 3.0+3.0+
Open-PackagePageOpen-PackagePage 使用指定封裝的 [專案]、[授權] 或 [報表濫用 URL] 來啟動預設瀏覽器。Launches the default browser with the project, license, or report abuse URL for the specified package. 3.0 + 中已淘汰Deprecated in 3.0+
註冊-TabExpansionRegister-TabExpansion 為命令的參數註冊 tab 鍵擴充,可讓您為常用的參數值建立自訂的擴充。Registers a tab expansion for the parameters of a command, allowing you to create customized expansions for commonly-used parameter values. 全部All
Sync-PackageSync-Package 從指定的專案取得已安裝套件的版本,並將版本同步處理至方案中的其餘專案。Get the version of installed package from specified project and syncs the version to the rest of projects in the solution. 3.0+3.0+
Uninstall-PackageUninstall-Package 移除專案中的封裝,並選擇性地移除其相依性。Removes a package from a project, optionally removing its dependencies. 全部All

如需有關主控台內任何這些命令的完整詳細說明,請執行下列命令,並提出問題:For complete, detailed help on any of these commands within the console, just run the following with the command name in question:

Get-Help <command> -full

所有套件管理員主控台命令都支援下列常用的 PowerShell 參數All Package Manager Console commands support the following common PowerShell parameters:

  • 偵錯Debug
  • ErrorActionErrorAction
  • ErrorVariableErrorVariable
  • OutBufferOutBuffer
  • OutVariableOutVariable
  • PipelineVariablePipelineVariable
  • 詳細資訊Verbose
  • WarningActionWarningAction
  • WarningVariableWarningVariable

如需詳細資訊,請參閱 PowerShell 檔中的about_CommonParametersFor details, refer to about_CommonParameters in the PowerShell documentation.