Versioning your assemblies through build pipelines

2019-06-21 | apurvghai | AzureDevOps | Yaml, Powershell


I love the idea of how we can simply match the build numbers and use them as a verison on the generated assembly. To do this, we can just write a short powershell script inside the pipeline. Please make sure to read my previous article on how to use custom variables here. It illustrates adding powershell tasks and using custom variables.

Once you are done with setting up your custom variables and powershell task. Then, our next step is to go and customize the .net based tasks arguments. We need to add a switch to the build and/or publish tasks depedening on .NET version you are using. Let’s the see the steps below:

I’m using this variable $CustomBuildNumber.

.NET Core

Go to build task and then to “Arguments” textbox

Add the switch called “version”

    --configuration $(BuildConfiguration) -p:Version=$(CustomBuildNumber)

Go to publish task and repeat the same

   --configuration $(BuildConfiguration) -p:Version=$(CustomBuildNumber) --output $(build.artifactstagingdirectory)

It is mandatory to add version to both build and publish for dotnet core

.NET Framework

Go to build task and then to “MS Build Arguments” textbox

Add the switch called “version”

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site" /p:Version=$(CustomBuildNumber)

This is an example based on App Service pipeline

When you add predefined pipeline for .net apps, "Publish symbols path" is added automatically. This contains version number field. We must set the field with the custom variable

version


Recent Posts
Develop your docs site with docfx
Dec 21, 20 | AzureDevOps
Versioning your assemblies through build pipelines
Jun 21, 19 | AzureDevOps
Customize your build number
Jun 21, 19 | AzureDevOps