同步套件 (visual Studio 中的 封裝管理員 主控台)

版本 3.0+;僅適用於 Windows 上 Visual Studio 中的 封裝管理員 主控台

從指定的 (或預設) 專案取得已安裝套件的版本,並將版本同步處理至方案中的其餘專案。

語法

Sync-Package [-Id] <string> [-IgnoreDependencies] [-ProjectName <string>] [[-Version] <string>]
    [[-Source] <string>] [-IncludePrerelease] [-FileConflictAction] [-DependencyVersion]
    [-WhatIf] [<CommonParameters>]

參數

參數 描述
Id (必要)要同步處理的封裝標識碼。-Id 參數本身是選擇性的。
IgnoreDependencies 只安裝此套件,而不是其相依性。
ProjectName 要同步處理封裝的項目,預設為預設專案。
版本 要同步處理的套件版本,預設為目前已安裝的版本。
來源 要搜尋之套件來源的 URL 或資料夾路徑。 本機資料夾路徑可以是絕對路徑,或相對於目前資料夾。 如果省略, Sync-Package 請搜尋目前選取的套件來源。
IncludePrerelease 在同步處理中包含發行前版本套件。
FileConflictAction 要求覆寫或忽略專案所參考之現有檔案時要採取的動作。 可能的值為 Overwrite、Ignore、None、OverwriteAll(3.0+)IgnoreAll
DependencyVersion 要使用的相依性套件版本,可以是下列其中一項:
  • 最低 (預設值):最低版本
  • HighestPatch:具有最低主要、最低次要、最高修補程式的版本
  • HighestMinor:具有最低主要、最高次要、最高修補程式的版本
  • 最高 (不含參數的 Update-Package 預設值):最高版本
您可以使用 檔案中的 Nuget.Config 設定來設定預設值dependencyVersion
Whatif 顯示執行命令時會發生什麼情況,而不需要實際執行同步處理。

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

一般參數

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

範例

# Sync the Elmah package installed in the default project into the other projects in the solution
Sync-Package Elmah

# Sync the Elmah package installed in the ClassLibrary1 project into other projects in the solution
Sync-Package Elmah -ProjectName ClassLibrary1

# Sync Microsoft.Aspnet.package but not its dependencies into the other projects in the solution
Sync-Package Microsoft.Aspnet.Mvc -IgnoreDependencies

# Sync jQuery.Validation and install the highest version of jQuery (a dependency) from the package source    
Sync-Package jQuery.Validation -DependencyVersion highest