EVERYTHING YOU NEED TO KNOW TO CREATE A SIMPLE SET UP PROJECT IN WIX TOOLSET

Introduction to WIX Toolset

WIX (Windows Installer XML) is the replacement for the traditional windows setup projects that was available prior to Visual Studio 2012. http://wixtoolset.org/

A typical WIX installer will look like this when run.

 

Create a Simple Set Up Project

To create a simple set up project select a Windows Installer XML project in Visual Studio. You have a few options here – but for now – we are just going to create simple setup project.

Once created, you should be greeted with the following screen.

Let’s break it down and take a closer look at the XML above….

First we start with a standard XML header:

<?xml version="1.0" encoding="UTF-8"?>

Next is a line giving summary details of the product we want to install, including its name and version:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

         <Product Id="*" Name="tryWix" Language="1033" Version="1.0.0.0" 

                 Manufacturer="" UpgradeCode="37b991e9-5444-4ae5-9e96-8372d3a2e2e2">

We also have some details about how the project is to be packaged up, what version of the installer we are using and what to do if it is already installed.

<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

The product section of the xml is finished with a list of features. And what component groups each feature is made up of:

<Feature Id="ProductFeature" Title="tryWix" Level="1">
              <ComponentGroupRef Id="ProductComponents" />
</Feature>

After the product section there is a fragment section. This is where the bulk of the setup details go. It lists the files and folder we will need to create and what component group they belong to. The component group is a link back to our features:

  <Fragment>
         <Directory Id="TARGETDIR" Name="SourceDir">
                  <Directory Id="ProgramFilesFolder">
                          <Directory Id="INSTALLFOLDER" Name="tryWix" />
                  </Directory>
         </Directory>
  </Fragment>

  <Fragment>
       <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
         <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order         to add resources to this installer. -->
         <!-- <Component Id="ProductComponent"> -->
         <!-- TODO: Insert files, registry keys, and other resources here. -->
         <!-- </Component> -->
       </ComponentGroup>
  </Fragment>
</Wix>

If we filled out the detail in the xml we might end up with something like this:

<?xml version="1.0" encoding="UTF-8"?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
         <Product Id="*" Name="tryWix" Language="1033" Version="1.0.0.0" Manufacturer="Company X" UpgradeCode="37b991e9-5444-4ae5-9e96-8372d3a2e2e2">
                 <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
 
                  <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
                 <MediaTemplate /> 
                 <Feature Id="ProductFeature" Title="tryWix" Level="1">
                          <ComponentGroupRef Id="ProductComponents" />
                          <ComponentGroupRef Id="ProductShortcuts" />
                 </Feature>
         </Product>
 
         <Fragment>
                 <Directory Id="TARGETDIR" Name="SourceDir">
                          <Directory Id="ProgramFilesFolder">
                                   <Directory Id="INSTALLFOLDER" Name="tryWix" />
                          </Directory>
 
                          <Directory Id="ProgramMenuFolder">
                                   <Directory Id="ProgramMenuSubfolder" Name="tryWix" />
                          </Directory>                          
                 </Directory> 
         </Fragment>
         
         <Fragment>
                 <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
                          <Component Id="ProductComponent">
                                   <File Id="AppFile1" Source="MyProgram.exe"/>
                          </Component> 
                 </ComponentGroup> 
                 <ComponentGroup Id="ProductShortcuts" Directory="ProgramMenuSubfolder"> 
                          <Component Id="ProductShortcut" Guid="76310258-7740-4008-A505-64CD36EE9173">
                                   <RegistryValue Root='HKCU' Key='Software\Manufacturer\Product'
                                                                               Name='InstallFolder)'
                                                                               Value='[INSTALLFOLDER]'
                                                                               Type='string' 
                                                                               KeyPath='yes' />
                                   
                                   <Shortcut Id="ProductShortcut1" Name="MyProgram" Description="My Application"
                                                                               Target="[INSTALLFOLDER]MyProgram.exe" WorkingDirectory="INSTALLFOLDER"/>
                                   <RemoveFolder Id="ProgramMenuSubfolder" On="uninstall"/>
                          </Component> 
                 </ComponentGroup> 
         </Fragment>
</Wix>

 

The above setup would install one file called MyProgram.exe to the programfiles\trywix folder. It will also create a Start Menu shortcut for us.

Up to now the installer had no UI. It will install the files directly without asking the user for anything.

WIX allows us to build our own custom UI, but it also has some built in dialogs that we can take advantage of.  We can add a simple dialog to ask the user for an install location by adding a UIRef element in our fragment node.

                 <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER"/>
                 <UIRef Id="WixUI_InstallDir" />

We will also need to add a reference in our project to the WixUIExtension.dll file.

Now, when we build and run the installer, we will get a couple of dialog screen including one for specifying the install location:

 

And there you have it….everything you need to know to create a simple set up project in WIX Toolset.

 

At Dataworks we enable the perfect hybrid of configurable off the shelf toolsets and custom software development to deliver innovative solutions to match your specific business process requirements.

This ensures we are the best at what we do.

If you would like to discuss how we can use our experience and expertise to deliver real benefits to your business please contact us today on 051 878555051 878555 or email info@dataworks.ie

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on whatsapp