GitVersion: [Bug] GitVersion.MsBuild does not set Azure DevOps build number

Hello,

I have a C# project that uses the GitVersionTask package. The project is built in an Azure DevOps pipeline. When running the build, the Azure DevOps build number is automatically set to the “FullSemVer”. However, after upgrading GitVersionTask to GitVersion.MsBuild, the build number is not set anymore.

Expected Behavior

GitVersion.MsBuild should set the Azure DevOps build number.

Actual Behavior

GitVersion.MsBuild does not set the Azure DevOps build number.

Additional Information

The log shows the following line:

Executing GenerateBuildLogOutput for 'AzurePipelines'.

However, it does not show this line:

Executing GenerateSetVersionMessage for 'AzurePipelines'.

From the git version code (src/GitVersionCore/Core/BuildAgentBase.cs), this indicates that the updateBuildNumber variable is false:

if (updateBuildNumber)
{
    writer($"Executing GenerateSetVersionMessage for '{GetType().Name}'.");
    writer(GenerateSetVersionMessage(variables));
}
writer($"Executing GenerateBuildLogOutput for '{GetType().Name}'.");

I tried adding a GitVersion.yml with update-build-number: true, however, it did not help.

Your Environment

  • Azure DevOps pipeline.
  • Repository does not contain GitVersion.yml. If I run gitversion /showconfig locally, update-build-number is set to true.
  • GitVersion.MsBuild 5.6.4

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 13
  • Comments: 17 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Hi,

I found this bug report while looking for this exact problem. We have just switched from GitVersionTask to GitVersion.MsBuild and we have the same issue.

Thanks, David

I landed here as I was looking for a similar issue I am having with Teamcity. I used the following to get the version in teamcity

  <Target Name="Update teamcity build number" AfterTargets="GetVersion"  Condition="'$(TEAMCITY_VERSION)' != ''">
    <Message Text="##teamcity[buildNumber '$(GitVersion_FullSemVer)']" Importance="High" />
  </Target>

It’s also possible to update the pipeline build number directly from the project file. You should add the following lines in your .csproj:

<Target Name="Update Version" BeforeTargets="Build" Condition="'$(TF_BUILD)' == 'true'">
   <Message Text="Version = $(GITVERSION_FullSemVer)" Importance="High" />
   <Message Text="##vso[build.updatebuildnumber]$(GITVERSION_FullSemVer)" Importance="High" />
</Target>

This should be fixed in 6.0.0-beta2