I'm trying to auto increment the version number with the builder number of my application through my Azure Devops pipeline.
I'm using semantic version: major.minor.patch, and I would like to add the build number to this.
But whatever I try, it always automatically appends a long string (the commit SHA hash) at the end of the informational version number.

I start my build in the following way:
--configuration Release --output $(Build.ArtifactStagingDirectory) --self-contained true --runtime win-x64 /p:Version=$(versionNumber) /p:InformationalVersion=$(versionNumber)+$(Build.BuildNumber)
I tried adding the build number to the normal Version like this:
/p:Version$(versionNumber)+$(Build.BuildNumber)
But that does not add the + Build Number.
Any ideas?
From your screenshot, the long string should be the commit hash.
The issue is from the .net8 SDK. It will include the commit SHA in the informational version automatically.
By default, Azure Pipelines will use .net8 to build the project now.
To solve this issue, you can add the <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion> to your csproj file.
For example:
<Project>
<PropertyGroup>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
</Project>
Or you can add the argument to your build task: /p:IncludeSourceRevisionInInformationalVersion=false
For example:
--configuration Release --output $(Build.ArtifactStagingDirectory) --self-contained true --runtime win-x64 /p:Version=$(versionNumber) /p:IncludeSourceRevisionInInformationalVersion=false /p:InformationalVersion=$(versionNumber)+$(Build.BuildNumber)
Or you can downgrade the .net version with the task: Use .NET Core
For more detailed info, you can refer to this ticket: Git commit ID included in assembly ProductVersion field when building with sdk 8
The property 'InformationalVersion' is used to set the product version, and the property 'Version' is used to set the file version.
Generally, a given version of the 'product' might include an EXE file and a number of DLLs files, and each file can have its own version (file version).
For your case, since you set the value of Build number (Build.BuildNumber) to be the automatically appends long string and set the value of 'InformationalVersion' to be '$(versionNumber)+$(Build.BuildNumber)', the product version will undoubtedly contain the long string.
If you do not want to contain the long string in the product version, you can remove '+$(Build.BuildNumber)' from the value of 'InformationalVersion'.
If you want to keep the build number contained in the product version but reset the value of build number to be another format, you can reference the documentation "Configure run or build numbers" to set the build number.
In addition, the "/p:Version$(versionNumber)+$(Build.BuildNumber)" has a wrong syntax, and the correct syntax should be "/p:Version=$(versionNumber)+$(Build.BuildNumber)". This will set the file version to contain the Build number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With