# Coordinating application and installer versions with WiX

One of the pains of maintaining an application and an installer for that application is tracking and incrementing the various version numbers. In a situation where you've got a single application and a single installer for that application, you may very well find it easiest for yourself and your users to have the installer and the application itself share the same version number.1

Remembering to set the versions in both the application and the installer is a pain and prone to error, so you're better off just linking them. For a WiX installer using harvesting, that's actually pretty easy to do. Assuming you're harvesting output files using the method I described in my last post, you've got a generated Output.wxs file in your installer project. Pop that open and look for the reference to your executable. It'll look something like this:

<File Id="fil6F19EC81FF06AC93EF5DE0BDA388F7EB" KeyPath="yes" Source="\$(var.Product.TargetDir)\Product.exe" />


The important part is the 'Id' - we can use that to reference the file (and its properties) elsewhere in our project. Specifically, in the 'Version' field of the 'Product' element in the primary installer file:

<Product Id="*" Name="Product"
Version="!(bind.FileVersion.fil6F19EC81FF06AC93EF5DE0BDA388F7EB)" ...>


We're using a light.exe binder variable to set the version (light is the linker which creates the .msi output). Now the version for the .msi will match whatever the version is set to in the executable; you only need to maintain it in one place.

1. I used to run into this in corporate environments all the time when creating applications which (for various bureaucratic reasons) weren't officially supported by IT. A user would have a problem, and question number one was "What version do you have installed?". The answer could very wildly depending on whether the user knew to look under "Help -> About", was looking at the "Add and Remove Programs" dialog, or was simply making something up. Keeping the installer and application versions coordinated fixes at least part of that problem.

Comment