Update-Package (Visual Studio 中的 封裝管理員 控制台)

僅適用於 Windows 上 Visual Studio 中的 NuGet 封裝管理員 控制台

更新 套件及其相依性,或專案中的所有套件,以更新版本。

語法

Update-Package [-Id] <string> [-IgnoreDependencies] [-ProjectName <string>] [-Version <string>]
    [-Safe] [-Source <string>] [-IncludePrerelease] [-Reinstall] [-FileConflictAction]
    [-DependencyVersion] [-ToHighestPatch] [-ToHighestMinor] [-WhatIf] [<CommonParameters>]

在 NuGet 2.8+ 中, Update-Package 可用來降級專案中的現有套件。 例如,如果您已安裝 Microsoft.AspNet.MVC 5.1.0-rc1,下列命令會將它降級為 5.0.0:

Update-Package Microsoft.AspNet.MVC -Version 5.0.0.

參數

參數 描述
Id 要更新之封裝的標識碼。 如果省略,請更新所有套件。 -Id 參數本身是選擇性的。
IgnoreDependencies 略過更新套件的相依性。
ProjectName 包含要更新之封裝的專案名稱,預設為所有專案。
版本 要用於升級的版本,預設為最新版本。 在 NuGet 3.0+ 中,版本值必須是最低、最高、HighestMinorHighestPatch其中一個(相當於 -保管庫)。
Safe 僅將升級限制為與目前安裝套件相同的主要和次要版本。
來源 要搜尋之套件來源的 URL 或資料夾路徑。 本機資料夾路徑可以是絕對路徑,或相對於目前資料夾。 如果省略, Update-Package 請搜尋目前選取的套件來源。
IncludePrerelease 包含更新的發行前版本套件。
重新安裝 使用其目前安裝版本的聚聚脂套件。 請參閱重新安裝和更新套件
FileConflictAction 要求覆寫或忽略專案所參考之現有檔案時要採取的動作。 可能的值為 Overwrite、Ignore、None、OverwriteAllIgnoreAll (3.0+)。
DependencyVersion 要使用的相依性套件版本,可以是下列其中一項:
  • 最低 (預設值):最低版本
  • HighestPatch:具有最低主要、最低次要、最高修補程式的版本
  • HighestMinor:具有最低主要、最高次要、最高修補程式的版本
  • 最高 (不含參數的 Update-Package 預設值):最高版本
您可以使用 檔案中的 Nuget.Config 設定來設定預設值dependencyVersion
ToHighestPatch 相當於 -保管庫。
ToHighestMinor 僅將升級限制為與目前安裝套件相同的主要版本。
Whatif 顯示執行命令時會發生什麼情況,而不需要實際執行更新。

這些參數都不接受管線輸入或通配符。

一般參數

Update-Package 支援下列 常見的 PowerShell 參數:D ebug、Error Action、ErrorVariable、OutBuffer、OutVariable、PipelineVariable、Verbose、WarningAction 和 WarningVariable。

範例

# Updates all packages in every project of the solution
Update-Package

# Updates every package in the MvcApplication1 project
Update-Package -ProjectName MvcApplication1

# Updates the Elmah package in every project to the latest version
Update-Package Elmah

# Updates the Elmah package to version 1.1.0 in every project showing optional -Id usage
Update-Package -Id Elmah -Version 1.1.0

# Updates the Elmah package within the MvcApplication1 project to the highest "safe" version.
# For example, if Elmah version 1.0.0 of a package is installed, and versions 1.0.1, 1.0.2,
# and 1.1 are available in the feed, the -Safe parameter updates the package to 1.0.2 instead
# of 1.1 as it would otherwise.
Update-Package Elmah -ProjectName MvcApplication1 -Safe

# Reinstall the same version of the original package, but with the latest version of dependencies
# (subject to version constraints). If this command rolls a dependency back to an earlier version,
# use Update-Package <dependency_name> to reinstall that one dependency without affecting the
# dependent package.
Update-Package Elmah –reinstall 

# Reinstall the Elmah package in just MyProject
Update-Package Elmah -ProjectName MyProject -reinstall

# Reinstall the same version of the original package without touching dependencies.
Update-Package Elmah –reinstall -ignoreDependencies