Mathias Olausson [MVP]

Archive for the ‘Build’ Category

Versioning files in TFS Build (vNext)

without comments


In my DevOps and Continuous Delivery presentations I’m always including a step in the build process where source files are updated with the current build number. This gives us an easy way to correlate the produced package to the build it came from, which is great for traceability.

Enough people have asked for the script so I feel I should post it here. It’s really nothing special, just a lightly customized version of the original sample script Andy Lewis wrote a long time ago. The sample comes from mine and Jakob’s book on Continuous Delivery so make sure to get a copy if you want more context.

The script will apply a version to the source files, for instance updating AssemblyInfo attributes like this:


Our script will also update the version number for database projects (DACPAC packages) and Android manifest files. It’s easy to extend the script to do the same for Wix projects (MSIs) or C++ (RC) files following the same principles.

All you need to do to add it to your source code repository and use a PowerShell build step to run the script. In our example you need to pass the build source directory and the build number to the task:


Download the complete script here (and rename it to .ps1).

Written by Mathias Olausson

March 27th, 2016 at 1:36 pm

Automatically update test plan with build number, take 2

without comments

A while back I wrote a PowerShell script to automatically update a test plan with the latest build number (

This script works well as long as the build server has permission to read and update test plans. But in some environments (such as when running on a hosted build agent in VSO) we need to do an explicit authentication. The solution I’ve choosen is to simply pass in credentials to the script and do an authentication before using the TFS API.

The script now takes two optional parameters if you want to authenticate, username and password, and you can just pass them in from the build definition.  You can use ether basic authentication and pass both or use the safer option and pass a Personal Access Token (PAT) in which case you only pass the PAT as the password.

Here’s an example where you go to manage your credentials in Visual Studio Online. First go to your profile:


From the Security tab you can either create a Personal Access Token:


Press Add to create an access token:


Copy the PAT (it cannot be retrieved later):


If you want to use basic authentication go to the Alternate authentication section and fill in the secondary username and password:


With this you are ready to use the script. Download the latest version from here:

Check in the script to Source control and update a Xaml build definition to use the script. In the following example I’ve used a PAT and only pass the token as the password:


Check out the old post if you want a step-by-step instruction on how to setup the build and test plan.

Written by Mathias Olausson

October 4th, 2015 at 12:50 pm

Build Status Badge for TFS 2015 and VSO

with 4 comments

A while back I wrote a post about how we can create a build bagde in TFS just like some of the other CI server can. It was actually really simple but since it was a custom extension it needed to be deployed outside of TFS, which of course is a bit of a pain. 

With TFS 2015 RC and the new build system I’m happy to see there is now a new feature that let’s you get a build badge automatically!

To get a build badge you just need to enable it on the build vNext build definition:


Note how nice the url to the badge is presented:


With this you can easily include the build badge in any web page. I really like the new Markdown support so I would include it in your wiki by simply point to in the badge url:


Save and it renders nicely like this:


So with this my suggestion on Uservoice can be closed.

Written by Mathias Olausson

May 6th, 2015 at 10:35 pm

Build Status Badge for TFS and Visual Studio Online

with one comment

With the new Markdown support in Visual Studio Online you can easily create a great project Wiki with information relevant to your team. One nice thing to have there is the build status(es), which for instance the AppVeyor build system provides as a small image – a build badge. Here’s how that could look in a Wiki page:


Adding the build badge is done by simply including an image element in the Markdown page:


I really like how easy it is to create mashups of different services to visualize data for the team using Markdown.

As for the build badge I think this is something that would be nice to have included in the product, if you think so too, vote on the following UserVoice suggestion:


But until that eventually happens we can always solve it ourselves. So what is needed to do this? It’s actually really simple, just write a service that looks up the build status and returns an image containing the badge.

In this example I’ve solved it by implementing a standard ASP.NET MVC application. I’ve used a controller that accepts a team project and build definition name as query string arguments:


for example;

http: //

This request will return a .png image like this:


Ok, so how did I do this? Let’s look at the code.

To make it easy to generate the badge I’ve created 150×30 px images to draw the image. The Images folder contains a couple of images like the one below, which we’ll then draw the status text on.


The code to generate a badge image is implemented as a MVC controller action. The code below gets the details from the latest build, draws the badge image and finally returns it as an image/png stream as the result:


GetBadgeDetails is a small helper function to give us the data to render on the badge image:


Finally the DrawRoundedRectangle renders the bounding rectangle for the badge:


To get the build data we need a couple of references to TFS:

  • Microsoft.TeamFoundation.Build.Client.dll
  • Microsoft.TeamFoundation.Client.dll

The code to get the TFS build details is as simple as this:


That’s all. Build and deploy to your favorite IIS server and you’re ready to start serving build badges for your team!

Download the complete sample here.

Written by Mathias Olausson

December 30th, 2014 at 10:26 pm

Posted in Build,TFS 2013,VSO