同版本的NuGet依赖

NuGet dependency of the same version

我想在我们的 TeamCity 构建服务器上自动生成 nuget 包。我们使用 TeamCity AssemblyInfo Patcher 使特定构建的所有 dll 具有相同的版本号。

我们从项目中生成了多个 NuGet 包。我如何在依赖项字段中指定版本号,以便它使用与正在构建的包相同的版本号 而无需在 NuGet .spec 文件 中对版本号进行硬编码?

例如,MyProject.Plugins 需要 MyProject.Math。所以对于 MyProject.Plugins 1.2.3.45,依赖应该是这样的:

<dependencies>
    <dependency id="MyProject.Math" version="1.2.3.45" />
</dependencies>

TeamCity 的 NuGet 包包含一个版本号字段。

如果您使用 AssemblyInfoPatcher,我们可以只使用我们在此处指定的编号。

对于使用文件内容替换器的更复杂的方法,从编译的 dll 中读取版本号的小型 PowerShell 脚本可以提供帮助并将其存储在 teamcity 配置参数 %ActualVersion%

$DllFileName = "MyDll.dll"
$PathPrefix = "bin/Release/"
$Version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($PathPrefix + $DllFileName).FileVersion
Write-Host "##teamcity[setParameter name='ActualVersion' value='$Version']"