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.
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:
Idattribute should change each time you build the MSI - the asterisk means it will be auto-generated
Versionattribute should probably come from your CI server
UpgradeCodeis 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.
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="126.96.36.199" 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 188.8.131.52, this snippet will also uninstall that.
It's important that
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>
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.