Wix Product Version with Build Script

Our projects are deployed with MSIs. Each MSI file is appended with the product version number (regular staff – major, minor, build number, revision number).

While this is enough for deployment, in production, it is hard to determine what product version is installed without either searching for assemblies to see the version, or some other piece of evidence. Today I decided to leverage Wix to generate the Product Version number, based on our NAnt script.

Nant script has all parts of product version defined as follow:

  1: <property name="version.major" value="1" />
  2: <property name="version.minor" value="7" />
  3: <property name="build.number" value="0" readonly="false"/>
  4: <property name="svn.revision" value="0" readonly="false"/>
  5: 
  6: <property name="project.version.full" 
  7:           value="${version.major}.${version.minor}.${build.number}.${svn.revision}" 
  8:           dynamic="true" readonly="false" />

Next step was updating Wix installer project file to include an external include file with a defined variable for product version, called ProductVersion, and apply that to project. Here’s partial Wix installer file:

  1: <?xml version="1.0" encoding="UTF-8"?>
  2: <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
  3: 
  4:   <?define build_dir = "$(var.ProjectDir)..\..\build\compile"?>
  5:   <?define documentation_dir = "$(var.ProjectDir)..\..\docs"?>
  6: 
  7:   <?include $(var.build_dir)\ProductVersion.wxi ?>
  8: 
  9:   <Product Id="5646ced5-d897-4978-b1d6-338e5baadbe9"
 10:        Name="COMPANY NAME $(var.ProductVersion)"
 11:        Language="1033"
 12:        Version="$(var.ProductVersion)"
 13:        Manufacturer="COMPANY NAME"
 14:        UpgradeCode="790b1905-c843-4973-a078-79874a7f30f2">
 15: 

Include file, ProductVersion.wxi is the one that should contain variable ProductVersion. This include is generated by nant script, injecting nant project.version.full variable.

Nant script to generate Wix include file:

<echo file="${build.compile.dir}\ProductVersion.wxi" message='&lt;?xml version="1.0" encoding="utf-8"?&gt;&#xA;&#xD;&lt;Include&gt;&#xA;&#xD;&lt;?define ProductVersion="${project.version.full}"?&gt;&#xA;&#xD;&lt;/Include&gt;' />

Which results in a file, that contains the required product version variable for Wix installer:

<?xml version="1.0" encoding="utf-8"?>
<Include>
  <?define ProductVersion="1.7.1234.4321"?>
</Include>

Once MSI is installed, Add/Remove programs contains the name with the version:

image

4 Comments

  • Interesting. Any reason you chose to use the .wxi file over using the -d command-line switch to candle.exe?

  • Rob,
    we have a solution (MSBuild) that has a project for custom actions, and the installer project itself. We leverage NAnt to invoke MSBuild on a solution file. I tried to pass parameters to MSBuild, but then it becomes way too complex (MSBuild is using a task for Wix). Plus why to re-invent the wheel with compiling each project in solution separately, if MSBuild task can do it all. Feel free to shed some light on the topic.

  • Interesting... just talked about using Wix today. Will have the team check out your post.

  • @Doug,
    we are using Wix for quiet a while (a bit less than a year) and it's probably one of the best ways to script an installer with build scripts. We looked into other ones, but it was the best candidate. And starting from Visual Studio 2010 it will be integrated into VS.

Comments have been disabled for this content.