Feel like a geek and get yourself Ema Personal Wiki for Android and Windows

28 June 2009

Using WIX to create an installer: quickstart tutorial

WIX is an open source, Microsoft-sponsored wrapper to create an MSI setup.

Because I quickly need to create a setup for a small project, and could not find a quick tutorial how to do this, I record the steps in this post for future reference. The success of a framework depends on its ability to get its users up-and-running with only one page of "getting started" reading.

1. Download and install Wix 3.0

2. Add a new Wix setup project to your existing solution for which you want to create a setup.

3. Add a project reference to the existing project from the Wix installer project.

4. Begin with the boilerplate xml
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="(create a new guid here)" Name="(application name here)" Language="1033" Version="" Manufacturer="(manifacturer name here)"
UpgradeCode="(create a new guid here)">
<Package InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="Media1.cab" EmbedCab="yes" />

5. Define the directories
    <Directory Id="TARGETDIR" Name="SourceDir">
<-- Program Files/app name -->
<Directory Id="ProgramFilesFolder">
<Directory Id="ApplicationRootDirectory" Name="(application name here)"/>
<-- Start menu/programs/app name -->
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="(application name here)"/>
<Directory Id="DesktopFolder" Name="Desktop"/>

6. Define contents of the application dir
    <DirectoryRef Id="ApplicationRootDirectory">
<Component Id="ApplicationFile" Guid="(create guid here)">
<File Id="ApplicationFile" Name="$(var.(project-to-install name).TargetFileName)"
Source="$(var.(project-to-install name).TargetPath)" DiskId="1" KeyPath="yes"/>
<Component Id="ConfigurationFile" Guid="(create guid here)">
<File Id="ConfigurationFile" Name="$(var.(project-to-install name).TargetFileName).config" Source="$(var.(project-to-install name).TargetPath).config"
DiskId="1" KeyPath="yes"/>

7. Define the contents of the start menu folder:
    <DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="(create guid here)">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="(application name here)"
Description="(nice description here)"
Target="[ApplicationRootDirectory](assemblyname here).exe"
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
<RegistryValue Root="HKCU" Key="Software\Microsoft\(application name here)" Name="installed" Type="integer" Value="1" KeyPath="yes"/>

8. Define the desktop shortcut
    <DirectoryRef Id="DesktopFolder">
<Component Id="DesktopShortcut" Guid="(create guid here)">
<RegistryKey Root="HKCU" Key="(app name here)\Install" Action="createAndRemoveOnUninstall">
<RegistryValue Name="Desktopshortcut" Value="1" Type="integer" KeyPath="yes"/>
<Shortcut Id="ApplicationDesktopShortcut"
Name="(app name here)"
Description="(nice description here)"
Target="[ApplicationRootDirectory](assembly name here).exe"

9. Tell installer to install the defined components
   <Feature Id="ProductFeature" Title="Main components" Level="1">
<ComponentRef Id="ApplicationFile" />
<ComponentRef Id="ConfigurationFile"/>
<ComponentRef Id="ApplicationShortcut"/>
<ComponentRef Id="DesktopShortcut"/>

10. And close the XML nicely

11. Build the installer and test it.

The created installer is one without any userinterface. It just installs what is has been told to install and doesn't ask the user for anything.

1 comment:

Anonymous said...

Any chance of seeing the XML in full? I'm slightly confused as to the positioning of the contents definition.