Useful WIX Snippets

On a recent WPF project, I spent a little time setting up our installer using WiX. Here's a useful collection of WIX configuration settings that I want to hang on to.

Product tag

Every WiX project has a Product tag. Here's an example:

<Product 
  Id="*" 
  Name="My Application" 
  Language="1033" 
  Version="1.0.0" 
  Manufacturer="You" 
  UpgradeCode="e0848881-1930-4d96-945b-fa8ad2813978"
  >

Some things to note about the various parts:

  • The Id attribute should change each time you build the MSI - the asterisk means it will be auto-generated
  • The Version attribute should probably come from your CI server
  • The UpgradeCode is used to determine whether the product was previously installed - once you set this, don't ever change it.

Ensure the .NET Framework is installed

This snippet checks whether .NET Framework 4.0 (full, not client profile) is installed, and if not, tells the user to go and install it.

<PropertyRef Id="NETFRAMEWORK40FULL"/>
<Condition Message="This application requires Microsoft .NET Framework 4.0 Runtime in order to run. Please install the .NET Framework and then run this installer again.">
  <![CDATA[Installed OR NETFRAMEWORK40FULL]]>
</Condition>

More information on the properties is available in the WixNetFxExtension documentation.

WixUI resources

If you are using WixUI, there are some properties you can override.

<UIRef Id="WixUI_Minimal" />
<UIRef Id="WixUI_ErrorProgressText" />
<WixVariable Id="WixUILicenseRtf" Value="Resources\License.rtf" />
<WixVariable Id="WixUIBannerBmp" Value="Resources\Banner.bmp" />
<WixVariable Id="WixUIDialogBmp" Value="Resources\Dialog.bmp" />
<WixVariable Id="WixUIExclamationIco" Value="Resources\Warning.ico" />
<WixVariable Id="WixUIInfoIco" Value="Resources\Information.ico" />

For the current build of WixUI, Banner.bmp should be 493x58, and Dialog.bmp should be 500x314.

Auto-uninstall previous versions

Suppose you release version 2.0 of your product. Here's a snipper to uninstall all previous versions upon installing 2.0:

<Upgrade Id="e0848881-1930-4d96-945b-fa8ad2813978">
  <UpgradeVersion
    Property="PREVIOUSFOUND"
    Minimum="0.0.0.0" IncludeMinimum="yes"
    Maximum="2.0.0.0" IncludeMaximum="yes"
    />
</Upgrade>
<InstallExecuteSequence>
  <RemoveExistingProducts After="InstallInitialize"/>
</InstallExecuteSequence>

Note that if you release a new build (i.e., Product/@Id changes, but Product/@Version doesn't) of 2.0.0.0, this snippet will also uninstall that.

It's important that Upgrade/@Id matches Product/@UpgradeCode.

Event source

If you hope to write to the event log, you'll need to be an administrator to create the event source. The installer is the best time to do this. Here's an example:

<DirectoryRef Id="TARGETDIR">
  <Component Id="RegistryEntries" Guid="8C29D953-4D25-4EE0-A7F2-A9B34C9C65EF">
    <util:EventSource
      Name="Training Kiosk"
      Log="Application"
      EventMessageFile="[NETFRAMEWORK40FULLINSTALLROOTDIR]EventLogMessages.dll"
      />
  </Component>
</DirectoryRef>

Run the application when installer finishes

After you install your WPF application, it's nice to run it automatically. Here's how:

<Property Id="WixShellExecTarget" Value="[#YourEXEFile]" />
<CustomAction 
  Id="LaunchApplication"
  BinaryKey="WixCA"
  DllEntry="WixShellExec"
  Impersonate="yes" 
  />

<UI>
  <Publish 
    Dialog="ExitDialog"
    Control="Finish"
    Event="DoAction"
    Value="LaunchApplication">NOT Installed</Publish>
</UI>
A picture of me

Welcome, my name is Paul Stovell. I live in Brisbane and work on Octopus Deploy, an automated deployment tool for .NET applications.

Prior to founding Octopus Deploy, I worked for an investment bank in London building WPF applications, and before that I worked for Readify, an Australian .NET consulting firm. I also worked on a number of open source projects and was an active user group presenter. I was a Microsoft MVP for WPF from 2006 to 2013.

14 Nov 2010

I want to note that:

If you are autogenerating your Product/@Id then you are doing a Major Upgrade.

see http://stackoverflow.com/questions/1431951/wix-product-id-should-be-autogenerated-for-patch-number-changes

14 Nov 2010

Good point Hüseyin. Going by the definition of major upgrade, that's exactly what I intended - uninstall the old version, and install a potentially completely different new version. As you point out, if that isn't your goal, then you may want to change the Id manually.

urza
urza
16 Nov 2010

Sorry for OT but: nice new blog design and colors :) your own work?

16 Nov 2010

Thanks urza. The design and rainbow graphic were from the Wordpress Spectrum theme, though the end result is a bit of a hybrid. It's part of a few new themes I created for FunnelWeb.