Labeling a build
Hi,
I'm trying to label a build in VCS based on the version provided in the project file. I've set-up Build feature to label my VCS. Furthermore I've created a powershell build step to read the version from the .csproj file and assign it to a parameter, which is then used in the VCS label build feature.
I'm now running into the issue that when I let my powershell script (see below) read the version from the .csproj, it will not label my build. However when I set the content of $version manually (e.g. to '1.2.3') It will label my build.
Also my build log shows then version is read correctly from the file:
12:48:22 Version found = 1.0.0
12:48:22 ProjectVersion set to 1.0.0
12:48:22 Process exited with code 0
I'm at a lost why it is not working with the version read from the file. Any help would be appriciated.
Powershell script (doesn't work):
$file = $pwd.Path + "\%AppName%\%AppName%.csproj"
$xml = [Xml] (Get-Content $file)
$version = $xml.Project.PropertyGroup.VersionPrefix.InnerText
Write-Output ("File = " + $file)
Write-Output ("Version found = " + $version)
Write-Host "##teamcity[setParameter name='ProjectVersion' value='$version']"
Write-Output ("ProjectVersion set to " + $version)
Powershell script (works, but is not what I want):
$file = $pwd.Path + "\%AppName%\%AppName%.csproj"
$xml = [Xml] (Get-Content $file)
$version = "1.2.3"
Write-Output ("File = " + $file)
Write-Output ("Version found = " + $version)
Write-Host "##teamcity[setParameter name='ProjectVersion' value='$version']"
Write-Output ("ProjectVersion set to " + $version)
Regards,
Patrick
Please sign in to leave a comment.
Patrick
Change
Thanks,
But I need the value of the VersionPrefix field, as Version is empty. Below is how my .csproj looks like.This strange contraption is because in some builds we need to add a VersionSuffix for NuGet publication.
Also removing the InnerText doesn't fix the issue.
Are you trying to build a.NET Core or .NET Can you post entire csproj file?
In any case whatever you use just change this
to
Hi Antonis,
I'm building a .NET Core 2.2 project. I've changed the line to your proposal, however it is still not labelling the build. I do still see in my build log it finds the version, but the label doesn't appear in our repository.
My csproj file looks like: