update 命令 (NuGet CLI)update command (NuGet CLI)

適用于: 套件耗•用量支援的版本: 全部Applies to: package consumption • Supported versions: all

將專案中的所有套件 (使用 packages.config) 更新為最新可用版本。Updates all packages in a project (using packages.config) to their latest available versions. 建議先執行「還原」, 然後再update執行。It is recommended to run 'restore' before running the update. (若要更新個別的封裝, nuget install請使用, 而不指定版本號碼, 在此情況下, NuGet 會安裝最新版本)。(To update an individual package, use nuget install without specifying a version number, in which case NuGet installs the latest version.)

注意: update不會使用在 Mono (Mac OSX 或 Linux) 下執行的 CLI, 或使用 PackageReference 格式時。Note: update does not work with the CLI running under Mono (Mac OSX or Linux) or when using the PackageReference format.

如果update參考已經存在, 此命令也會更新專案檔中的元件參考。The update command also updates assembly references in the project file, provided those references already exist. 如果更新的封裝有已加入的元件, 則會加入新的參考。If an updated package has an added assembly, a new reference is not added. 新的封裝相依性也不會新增其元件參考。New package dependencies also don't have their assembly references added. 若要將這些作業納入做為更新的一部分, 請使用套件管理員 UI 或套件管理員主控台, 更新 Visual Studio 中的封裝。To include these operations as part of an update, update the package in Visual Studio using the Package Manager UI or the Package Manager Console.

此命令也可以用來使用 -self旗標來更新 nuget.exe 本身。This command can also be used to update nuget.exe itself using the -self flag.

使用量Usage

nuget update <configPath> [options]

其中<configPath> , 會識別packages.config列出專案相依性的或方案檔。where <configPath> identifies either a packages.config or solution file that lists the project's dependencies.

選項Options

選項Option 描述Description
ConfigFileConfigFile 要套用的 NuGet 設定檔。The NuGet configuration file to apply. 如果未指定, %AppData%\NuGet\NuGet.Config則會使用 ( ~/.nuget/NuGet/NuGet.Config Windows) 或 (Mac/Linux)。If not specified, %AppData%\NuGet\NuGet.Config (Windows) or ~/.nuget/NuGet/NuGet.Config (Mac/Linux) is used.
FileConflictActionFileConflictAction 指定當系統提示您覆寫或忽略專案所參考的現有檔案時, 所要採取的動作。Specifies the action to take when asked to overwrite or ignore existing files referenced by the project. 值為overwrite、ignore、noneValues are overwrite, ignore, none.
ForceEnglishOutputForceEnglishOutput (3.5 +) 強制使用非變異的英文文化特性來執行 nuget.exe。(3.5+) Forces nuget.exe to run using an invariant, English-based culture.
HelpHelp 顯示命令的說明資訊。Displays help information for the command.
IDId 指定要更新之套件識別碼的清單。Specifies a list of package IDs to update.
MSBuildPathMSBuildPath (4.0 +) 指定要搭配命令使用之 MSBuild 的路徑, 其優先順序高於-MSBuildVersion(4.0+) Specifies the path of MSBuild to use with the command, taking precedence over -MSBuildVersion.
MSBuildVersionMSBuildVersion (3.2 +) 指定要搭配此命令使用的 MSBuild 版本。(3.2+) Specifies the version of MSBuild to be used with this command. 支援的值為4、12、14、15.1、15.3、15.4、15.5、15.6、15.7、15.8、15.9。Supported values are 4, 12, 14, 15.1, 15.3, 15.4, 15.5, 15.6, 15.7, 15.8, 15.9. 根據預設, 會挑選路徑中的 MSBuild, 否則會預設為 MSBuild 的最高安裝版本。By default the MSBuild in your path is picked, otherwise it defaults to the highest installed version of MSBuild.
NonInteractiveNonInteractive 抑制使用者輸入或確認的提示。Suppresses prompts for user input or confirmations.
PreReleasePreRelease 允許更新為發行前版本。Allows updating to prerelease versions. 更新已安裝的發行前版本套件時, 不需要此旗標。This flag is not required when updating prerelease packages that are already installed.
RepositoryPathRepositoryPath 指定安裝封裝的本機資料夾。Specifies the local folder where packages are installed.
SafeSafe 指定只會安裝與已安裝的封裝在相同的主要和次要版本中可用的最高版本更新。Specifies that only updates with the highest version available within the same major and minor version as the installed package will be installed.
SelfSelf 將 nuget.exe 更新為最新版本;所有其他引數都會被忽略。Updates nuget.exe to the latest version; all other arguments are ignored.
SourceSource 指定要用於更新的套件來源清單 (如 Url)。Specifies the list of package sources (as URLs) to use for the updates. 如果省略, 此命令會使用設定檔中提供的來源, 請參閱一般的 NuGet設定。If omitted, the command uses the sources provided in configuration files, see Common NuGet configurations.
VerbosityVerbosity 指定輸出中顯示的詳細資料量: [一般]、[無訊息]、[詳細]。Specifies the amount of detail displayed in the output: normal, quiet, detailed.
VersionVersion 與一個封裝識別碼搭配使用時, 會指定要更新的封裝版本。When used with one package ID, specifies the version of the package to update.

另請參閱環境變數Also see Environment variables

範例Examples

nuget update

# update packages installed in solution.sln, using MSBuild version 14.0 to load the solution and its project(s).
nuget update solution.sln -MSBuildVersion 14

nuget update -safe

nuget update -self