Versioning SharePoint Add-Ins in your VSO Scripted Build

In a previous post I wrote a bit about building your SharePoint Apps (or Add-Ins as they are now called) using the new scriptable build system in Visual Studio Online.

But there was a slight problem with this approach as it would always produce add-in packages with the version number from the AppManifest.xml file. And if you are working in a team where everybody keeps their version number at all built add-ins keep this single version. This is maybe ok if you are doing production stuff and you want to avoid triggering updates. But if you are still developing and testing this makes traceability harder and so I decided that the add-in versioning should be part of the build process and not depend on people updating manifest files.


The new build system has excellent support for PowerShell, so I created a simple script for automatically versioning my Add-Ins during the build. In this script I will take the generated build number, which is in the format of Year.MonthDay.Index by default, and add that after the major version number. So todays first build should produce an add-in with the version number of 1.2015.1018.1

The Script
Write-Host "Versioning started"

# Apply buildnumber to manifest files
$buildNumber = $Env:BUILD_BUILDNUMBER
$buildNumberYear = $buildNumber.Substring(0,4)
$buildNumberDay = $buildNumber.Substring(4,4)
$buildNumberIndex = $buildNumber.Split(".")[1]

# Apply the buildnumber to the manifest files
$files = Get-ChildItem -Path $PSParentPath -Filter AppManifest.xml -Recurse

if ($files)
	Write-Host "Will apply $buildNumber to $($files.count) files."
	foreach ($file in $files) {
		[System.Xml.XmlDocument] $doc = new-object System.Xml.XmlDocument
		$doc.App.Version = "1." + $buildNumberYear + "." + $buildNumberDay + "." + $buildNumberIndex
		Write-Host "$($file.FullName) - version applied"
	Write-Warning "No Manifest files found."

Using the file is easy as you just need to make sure the Visual Studio build servers have access to it. I usually include it in the solution, but outside the main application project structure.


Setting it up

VSO has PowerShell steps that allow you to run scripts at any phase during the build. For versioning, this step should take place before we do a build using the Visual Studio build step.

  1. Add a PowerShell step to your build
  2. Select the path to the script, no parameters needed.

All set and ready to go:



You can download the script here.

Happy building (with VSO),