Visual Studio) 中的 Update-Package (封裝管理員主控台Update-Package (Package Manager Console in Visual Studio)

僅適用于 Windows 上 Visual Studio 的 NuGet 封裝管理員主控台 內。Available only within the NuGet Package Manager Console in Visual Studio on Windows.

將封裝及其相依性或專案中的所有封裝更新為較新的版本。Updates a package and its dependencies, or all packages in a project, to a newer version.

SyntaxSyntax

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 可以用來將專案中的現有套件降級。In NuGet 2.8+, Update-Package can be used to downgrade an existing package in your project. 例如,如果您已安裝 5.1.0 rc1,則下列命令會將它降級為5.0.0:For example, if you have Microsoft.AspNet.MVC 5.1.0-rc1 installed, the following command would downgrade it to 5.0.0:

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

參數Parameters

參數Parameter DescriptionDescription
IdId 要更新之封裝的識別碼。The identifier of the package to update. 如果省略,則會更新所有套件。If omitted, updates all packages. -Id 參數本身是選擇性的。The -Id switch itself is optional.
IgnoreDependenciesIgnoreDependencies 略過更新套件的相依性。Skips updating the package's dependencies.
ProjectNameProjectName 包含要更新之封裝的專案名稱,預設為所有專案。The name of the project containing the packages to update, defaulting to all projects.
版本Version 要用於升級的版本,預設為最新版本。The version to use for the upgrade, defaulting to the latest version. 在 NuGet 3.0 + 中,版本值必須是 最低、最高、HighestMinorHighestPatch 的其中一個 (相當於-Safe) 。In NuGet 3.0+, the version value must be one of Lowest, Highest, HighestMinor , or HighestPatch (equivalent to -Safe).
保險箱Safe 將升級限制為只有與目前安裝的套件具有相同主要和次要版本的版本。Constrains upgrades to only versions with the same Major and Minor version as the currently installed package.
來源Source 要搜尋之套件來源的 URL 或資料夾路徑。The URL or folder path for the package source to search. 本機資料夾路徑可以是絕對或相對於目前資料夾的路徑。Local folder paths can be absolute, or relative to the current folder. 如果省略,則會 Update-Package 搜尋目前選取的封裝來源。If omitted, Update-Package searches the currently selected package source.
IncludePrereleaseIncludePrerelease 包含更新的發行前版本套件。Includes prerelease packages for updates.
重新安裝Reinstall 使用其目前安裝的版本 Resintalls 封裝。Resintalls packages using their currently installed versions. 請參閱 重新安裝和更新套件See Reinstalling and updating packages.
FileConflictActionFileConflictAction 當系統要求覆寫或忽略專案所參考的現有檔案時,所要採取的動作。The action to take when asked to overwrite or ignore existing files referenced by the project. 可能的值為 覆寫、忽略、無、OverwriteAllIgnoreAll (3.0 +) 。Possible values are Overwrite, Ignore, None, OverwriteAll , and IgnoreAll (3.0+).
DependencyVersionDependencyVersion 要使用之相依性套件的版本,它可以是下列其中一項: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
  • 不含參數的 Update-Package 最高 (預設值) :最高版本Highest (default for Update-Package with no parameters): the highest version
您可以使用檔案中的設定來設定預設值 dependencyVersion Nuget.ConfigYou can set the default value using the dependencyVersion setting in the Nuget.Config file.
ToHighestPatchToHighestPatch 相當於-Safe。equivalent to -Safe.
ToHighestMinorToHighestMinor 將升級限制為只有與目前安裝的套件具有相同主要版本的版本。Constrains upgrades to only versions with the same Major version as the currently installed package.
WhatIfWhatIf 顯示執行命令時會發生什麼事,而不實際執行更新。Shows what would happen when running the command without actually performing the update.

這些參數都不接受管線輸入或萬用字元。None of these parameters accept pipeline input or wildcard characters.

一般參數Common Parameters

Update-Package 支援下列 常見的 PowerShell 參數: Debug、Error Action、ErrorVariable、OutBuffer、OutVariable、PipelineVariable、Verbose、WarningAction 和 WarningVariable。Update-Package supports the following common PowerShell parameters: Debug, Error Action, ErrorVariable, OutBuffer, OutVariable, PipelineVariable, Verbose, WarningAction, and WarningVariable.

範例Examples

# 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