How To Set WiX Installer Version to the Current Build Version

Written by Radu Popescu · June 7th, 2021 · 3min read

Do you need your installer to keep its current build version? In this article, will go through all the steps you need to set your WiX installer version to the current build version.

Start with Your Base Application

We will use a hypothetical scenario using WiX Toolset version 3.11.2 to help illustrate how to set a WiX installer version to the current build version.

For this example, the first thing we have to do is create a sample basic application containing an executable file called “CMtrace.exe” and a text file called “guide.txt” that includes the information shown below.

Text file

It is important to look inside the WiX installer project code since it will be the one modified through the updating version process.

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="A0174BDA-E73A-4238-802E-6C8D5E427668" UpgradeCode="8127636F-6291-4D43-8CC9-AB702A631C3B" 
Name="SampleApp" Version="1.0.0.0" Manufacturer="Caphyon" Language="1033">
<PackageId="075454EB-3FD5-4FA9-9701-1AA510A1D56F" InstallerVersion="200" Compressed="yes" Comments="Test sample app installer"/>
<MediaTemplate />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="SampleApp">
<Component Id="Files" Guid="11111111-2222-3333-4444-555555555555">
<File Id="File1" Source="CMTrace.exe"/>
<File Id="File2" Source="guide.txt"/>
</Component>
</Directory>
</Directory>
</Directory>
 
<Feature Id="Feature1" Level="1" Title="First feature" Description="This is the one and only feature in this installation">
<ComponentRef Id="Files"/>
</Feature>
</Product>
</Wix>

Using Binder Variables to Pass the Product Version of the Current Build Version

If we take a look in our code, we see that the <Product [...] Version=”1.0.0.0”> and the version value is hardcoded. What we want to achieve is to update the version of our main executable file to the actual Product Version.

Doing that is pretty simple, we just need to use Binder Variables.

Binder Variables are properties that are not available until the linker is about to generate or bind the final output. The supported binder variables are All Versioned Files, Assemblies, Properties, Package Properties, Localization Variables, and Custom Binder Variables.

NoteFor an in-depth description of supported binder variables and examples, you can consult this article.

First, we have to pass the version of our CMTrace.exe file to our Product. For that, we need to take a look at our file declaration section.

<File Id="File1" Source="CMTrace.exe"/> 

For this example, we are using the “All Versioned Files” “bind.fileVersion.FileID” binder variable, where FileID is the value of our CMtrace.exe File Id and is equal to “File1”.

Now, all we need to do is replace the hard coded version from the <Product [...] Version=”1.0.0.0”> section, with the following syntax:

 <Product [...] Version="!(bind.FileVersion.File1)" 

This is how our code should look like:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="A0174BDA-E73A-4238-802E-6C8D5E427668" UpgradeCode="8127636F-6291-4D43-8CC9-AB702A631C3B" 
Name="SampleApp" Version=”!(bind.FileVersion.File1)” Manufacturer="Caphyon" Language="1033">
<PackageId="075454EB-3FD5-4FA9-9701-1AA510A1D56F" InstallerVersion="200" Compressed="yes" Comments="Test sample app installer"/>
<MediaTemplate />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="SampleApp">
<Component Id="Files" Guid="11111111-2222-3333-4444-555555555555">
<File Id="File1" Source="CMTrace.exe"/>
<File Id="File2" Source="guide.txt"/>
</Component>
</Directory>
</Directory>
</Directory>
 
<Feature Id="Feature1" Level="1" Title="First feature" Description="This is the one and only feature in this installation">
<ComponentRef Id="Files"/>
</Feature>
</Product>
</Wix>

And, that's it! You can now set the WiX Installer version to the current build version.

For more useful guides and tutorials, make sure to check our dedicated page to the WiX open-source technology, where you can find everything from the basic principles of the WiX Toolset to more advanced tips for developers and IT Pros.

Get the most from packaging with Advanced Installer

Try the 30-day fully-featured edition absolutely free!

Advanced Installer Architect edition