Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you extract a version number from nuspec into TeamCity?

How do you extract a version number from nuspec into TeamCity?

We have a csproj file with this corresponding nuspec node:

1.3.2

In TeamCity I'd like to do a build of this project and create a NuGet package with version 1.3.2.%build.counter%. For example, 1.3.2.322. It is important the version number is coming from a file within source control (the NuSpec) and I don't want to duplicate this as a variable in TeamCity. Is there a way to extract 1.3.2 from the NuSpec file and use it as a TeamCity variable?

like image 240
infojolt Avatar asked Nov 21 '14 15:11

infojolt


1 Answers

This approach works with version 10+ of TeamCity and gets around issues with Select-Xml and namespaces.

$Version = ([xml](Get-Content .\MyProject.nuspec)).package.metadata.version
$BuildCounter = %build.counter%

echo "##teamcity[setParameter name='PackageVersion' value='$Version.$BuildCounter']"
like image 111
Matt Canty Avatar answered Oct 15 '22 03:10

Matt Canty