Sync-Package(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 要从中同步包的项目,默认为默认项目。
版本 待同步包的版本,默认为当前安装的版本。
Source 要搜索的包源的 URL 或文件夹路径。 本地文件夹路径可为绝对路径,也可为相对于当前文件夹的路径。 如果省略,Sync-Package 则会搜索当前选择的包源。
IncludePrerelease 在同步中包括预发行包。
FileConflictAction 当系统要求覆盖或忽略项目所引用的现有文件时要执行的操作。 可能的值为 Overwrite、Ignore、None、OverwriteAll(3.0 及以上版本)IgnoreAll
DependencyVersion 待使用依赖项包的版本,它可为以下版本之一:
  • Lowest(默认值):最低版本
  • HighestPatch:具有最低主要、最低次要、最高修补程序的版本
  • HighestMinor:具有最低主要、最高次要、最高修补程序的版本
  • 最高(不带参数的 Update-Package 的对应默认值):最高版本
可使用 Nuget.Config 文件中的 dependencyVersion 设置来设置默认值。
WhatIf 显示运行此命令而不实际执行同步时会出现什么情况。

这些参数均不接受管道输入或通配符字符。

通用参数

Sync-Package 支持以下常见 PowerShell 参数:Debug、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