I have the following simple build pipeline working in Azure DevOps with releases deployed to a staging slot.
I would like to have a build revision/version string and that is auto-incremented. I then want to display this in my web app so I can tell which version of the software is in production.
Currently I display the version string from the .csproj file. Something like this in a
<Version>1.1.4.7</Version>
And then displayed on a web page using the following code:
Version: @typeof(Startup).Assembly.GetName().Version.ToString()
If I can update the existing version string that would be great but I'm open to changing to whatever's easiest to integrate in the CI process.
Versioning has been simplified in the .Net Core world.
Edit your csproj and modify it as follows:
<PropertyGroup>
<Version Condition=" '$(BUILD_BUILDNUMBER)' == '' ">1.0.0.0</Version>
<Version Condition=" '$(BUILD_BUILDNUMBER)' != '' ">$(BUILD_BUILDNUMBER)</Version>
</PropertyGroup>
If your file doesn’t have a version node, add the above.
The above setup will mean debugging locally will give you a version of 1.0.0.0, and in the event, you build in a non-Azure DevOps environment you will also end up with a 1.0.0.0 version. $(BUILD_BUILDNUMBER) is an environment variable set by Team Build and which will be updated at build time by VSTS or TFS.
The .Net version needs to be in the format [major].[minor].[build].[revision] with each segment being a number between 0 and 65000. You can configure the build number format in the Options tab, see here more info about the formatting. See here for helpful steps on configuring the build.