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

5 comments
Comment actions Permalink

Patrick

Change 

 

$version = $xml.Project.PropertyGroup.VersionPrefix.InnerText

to

$version = $xml.Project.PropertyGroup.Version

0
Comment actions Permalink

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.

  <PropertyGroup Condition=" '$(Version)' == '' ">
    <VersionPrefix Condition=" '$(VersionPrefix)' == '' ">1.0.0</VersionPrefix>
    <Version Condition=" '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</Version>
    <Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
  </PropertyGroup>
0
Comment actions Permalink

Are you trying to build a.NET Core or .NET Can you post entire csproj file?

0
Comment actions Permalink

In any case whatever you use just change this

$version = $xml.Project.PropertyGroup.VersionPrefix.InnerText

to

$version = $xml.Project.PropertyGroup.VersionPrefix.InnerXml
0
Comment actions Permalink

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.

08:27:07 File = D:\TeamCity\work\8523553de9be545\Service.Web\Service.Web.csproj
08:27:07 Version found = 1.0.0
08:27:07 ProjectVersion set to 1.0.0

My csproj file looks like:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition=" '$(Version)' == '' ">
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">1.0.0</VersionPrefix>
<Version Condition=" '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</Version>
<Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>C:\Projects\libraries\Service.Web\Service.Web\Service.Web.xml</DocumentationFile>
<NoWarn>1701;1702;1591;1573</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>C:\Projects\libraries\Service.Web\Service.Web\Service.Web.xml</DocumentationFile>
<NoWarn>1701;1702;1591;1573</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />

<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />
<PackageReference Include="Serilog.Sinks.RollingFileAlternate" Version="2.0.9" />
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" />
</ItemGroup>

</Project>

 

0

Please sign in to leave a comment.