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="184.108.40.206" 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 220.127.116.11, 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>
Hello, I'm Paul Stovell
I'm a Brisbane-based software developer, and founder of Octopus Deploy, a DevOps automation software company. This is my personal blog where I write about my journey with Octopus and software development.
I write new blog posts about once a month. Subscribe and I'll send you an email when I publish something new.Subscribe