Visual Studio Online build version increment

14 Jan 2016 by Ryan Ververs-Bijkerk

Category:

    Development

Visual Studio Online build version increment

Table of Content

  • Important note
  • The problem and solution
  • Conclusion

I’m currently using Visual Studio Online for my tooling and I was searching for a way to increment the build version for my solution. After searching the internet I found the following blog post which I applied, but for some reason it was not working as expected. I’m not using a default version format and this was causing the build to fail. In this blog post I’m going to share how I fixed it.

Important note

Before I start, I want to point out the best practices regarding .NET assembly versioning which can be found here.

The problem and solution

I created the variables as the blog post described and set the build format number “$(BuildDefinitionName)_$(MajorVersion).$(MinorVersion)$(Rev:.r)” which is like 1.0.1.

Before running a build I have added the “ApplyVersionToAssemblies.ps1” script and included the PowerShell script in a build step. Next step is starting a build but it failed with the following PowerShell error:

Could not find version number data in BUILD_BUILDNUMBER.

Looking into the script this the error is caused by the the RegEx check which is for finding the version number from the build format property. Because I’m not using a standard formatting number the script is expecting a build number like 0.0.0.0. In order to fixes the error we need to modify the “ApplyVersionToAssemblies.ps1”. On line 16 in the regular expression is defined and I modified to the following:

# Regular expression pattern to find the version in the build number 
# and then apply it to the assemblies
$VersionRegex = "\d+\.\d+\.\d+"

After the modification the build was successful and the version was applied correctly.

Conclusion

With some small modification in the “ApplyVersionToAssemblies.ps1” PowerShell script it is possible to modify the build format. I took me some time to figure it out and get it working so I hope it helps a bit.

Sources:

https://msdn.microsoft.com/Library/vs/alm/Build/scripts/index

http://blogs.msdn.com/b/jjameson/archive/2009/04/03/best-practices-for-net-assembly-versioning.aspx

http://incyclesoftware.com/2015/06/vnext-build-awesomeness-managing-version-numbers/

Tags:
    development
    powershell
    visual studio online
Ryan Ververs-Bijkerk
Written by Ryan Ververs-Bijkerk

Ryan is a self-employed technologist at GO-INIT who specializes in the EUC and code area. He primarily focuses on the user experience in centralized desktop environments.

Search

    Follow me

    Community