Pages

Tuesday, October 29, 2013

How to get dynamic versioning using WiX and TFS continuous integration

First and foremost, I owe this post to Chris Painter(@chrpai).  He, on his own time, walked me through the steps on how to get this dynamic versioning setup in TFS and WiX.  He saved me tons of time and I really appreciate his generosity.

As a professional software developer I believe that having a continuous integration setup is par for the course.  I used to live in a world where I would come into work on a Monday morning and find "the build" broken.  Mind you this was right before someone wanted to demo the software.  I have vowed that I will not work without the CI safety net.

Today I needed to get my latest application installer versioned.  I want it to version each time I check in and my CI build runs.  I want it to be as simple as possible.  In particular I am not yet ready to go the custom activity route.  I spent a considerable amount of time on Stack Overflow and the WiX forums looking for an answer, but with no avail.  Without further ado here is the solution

1.     From TFS open your build process template in the xaml designer.  You can find the path hyperlinked from the Build Process page


2.     While you are here go ahead and setup the format of your versioning.  You can do that like this. 


You can choose your own versioning method, but let me explain this one.  First the _ after $(BuildDefinitionName) is important because we are going to use it to parse later.  Everything after the _ will be the version.  You can see that mine is  3.0.YearDayOfYear.Rev.  This will give me a version like this 3.0.13302.1 if the build is the first build on Oct 29th, 2013.

3.     Back to the xaml workflow. Navigate to the “Run MSBuild for Project” step in the tree.  It is pretty deep in the hierarchy.  See the picture below.

4.     Open the Properties of this build step and modify the CommandLineArguments property to something like this. Notice I am splitting on that _ I talked about earlier.

String.Format("/p:SkipInvalidConfigurations=true {0} /p:MSIProductVersion={1}", MSBuildArguments, BuildDetail.BuildNumber.Split(New Char() {"_"c}).Last())

5.     Save your workflow template and check it into TFS under the BuildProcessTemplates folder.

6.     Make sure your build definition references the modified build workflow you just checked in and save your build definition.

7.     Queue your build and install your product.  You should now have a dynamically generated version number for your product that you can trace back to the date and version of source code you build.



This solves a small part of the whole equation of installer creation.  It’s a huge topic with a lot of available customization.  Chris Painter helped me get this far and has also showed me a great tool he created at https://iswix.codeplex.com/, which opens up a great number of possibilities without having to know all the low level details of WiX itself.

1 comment:

  1. Thanks, this walk-through is exactly what needed.

    ReplyDelete