Recently, I had to create a build pipeline for a small console application in Azure Pipelines for a customer. Personally, I prefer to handle versioning of software so that the version number is represented like this: 2020.8.24.2, where a last number is a revision number and those before are the current date. In this case, it’s always possible to track the version of the software which an end-user is using and immediately know when it was released. This can be rather important if there is a need to validate, identify, or correct bugs.

If you would also like to do this you just need to follow these steps:

1. First, you need to update the project files *.csproj so that they contain a ‘Version’ field like below; this goes for all the projects in your solution that you want to version:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
	<Version>1.0.1</Version>
	<Authors>Christian Andersen</Authors>

2. Next, you need to edit your build Option Build number format to:

$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)

3. In the Options tab when you edit the pipeline:

4. And update your pipeline build task command arguments to look like this:

"--configuration $(BuildConfiguration) --no-restore /p:Version=$(Build.BuildNumber)"

5. And then publish the task to look like this:

--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory) /p:Version=$(Build.BuildNumber)

Now, you can build your packages and they will have versioning described above. You can check this by hovering with the mouse over the binary files in Windows.

Last modified: April 23, 2022

Author

Comments

Write a Reply or Comment

Your email address will not be published.