I want to generate nuget packages automatically on our TeamCity build server. We use TeamCity AssemblyInfo Patcher to make all dlls of a specific build have the same version numbers.
We generate multiple NuGet packages from our project. How can I specify the version number in the dependency field so that it uses the same number than for the package that is being built without hardcoding the number in the NuGet .spec file?
As an example, MyProject.Plugins
requires MyProject.Math
. So for MyProject.Plugins 1.2.3.45
, the dependency should look like this:
<dependencies>
<dependency id="MyProject.Math" version="1.2.3.45" />
</dependencies>
TeamCity's NuGet pack includes a version number field.
If you use AssemblyInfoPatcher, we can just use the number we specify there.
For more complex approaches using File Content Replacer, a small PowerShell script that reads the version number out of the compiled dll can help and stores it in the teamcity configuration parameter %ActualVersion%
$DllFileName = "MyDll.dll"
$PathPrefix = "bin/Release/"
$Version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($PathPrefix + $DllFileName).FileVersion
Write-Host "##teamcity[setParameter name='ActualVersion' value='$Version']"