Automatically Increment WiX Installer Product Version

Most build servers set an environment variable BUILD_NUMBER on every build that is auto-incremented. We can do this using WiX proprocessor. (Note, the link is for WiX 2.0 Manual, I couldn’t find a reference for WiX 3.0 Preprocessor.  Maybe it’s the same? Probably not.)

I wanted to increment my WiX installers Product Version field automatically based off this number.

Here’s the top of my Product.wxs:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

  <!-- Set version based on build_number env. variable. -->
  <?ifdef env.BUILD_NUMBER ?>
    <?define PRODUCTVERSION="1.0.$(env.BUILD_NUMBER).0"?>
  <?else?>
    <?define PRODUCTVERSION="1.0.0.0"?>
  <?endif?>

  <Product Id="THE_GUID_YOU_GENERATED"
           Name="My Application Name"
           Language="1033"
           Version="$(var.PRODUCTVERSION)"
           Manufacturer="My Manufacturer Name"
           UpgradeCode="THE_GUID_YOU_GENERATED">

...

The ifdef part is very picky. At first I tried <?ifdef $(env.BUILD_NUMBER) ?>, which totally doesn’t work. Then I tried <?ifdef BUILD_NUMBER ?>, which also totally doesn’t work. The above is the only thing I could get to work, which goes against what this guy says. The WiX documentation for the preprocessor is pretty shoddy.

Also notice that I am incrementing the 3rd of the 4 version numbers. Why? No idea. Maybe you can tell me.

So YMMV, Caveat Emptor, and all the crap.

WiX Arcanum!

Comments (1) left to “Automatically Increment WiX Installer Product Version”

  1. Nicholas Piasecki wrote:

    Thanks for posting this! I was trying to use ifdef $(env.BUILD_NUMBER) [with the parentheses] instead of without.

    As for incrementing the 3rd of the 4 version numbers, I believe that’s because Windows Installer only checks the first three version numbers when doing upgrade checks, even though the rest of Microsoft has standardized on a four-part version string.

Post a Comment

*Required
*Required (Never published)