Click here to Skip to main content
15,886,362 members
Articles / Web Development / HTML
Tip/Trick

Key Points while getting started with WiX

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
26 Feb 2015CPOL2 min read 10K   80   8  
This article will give a brief introduction about WIX toolset that builds Windows installation packages from XML source code with an example

Introduction

I went through many article on the internet but they didn't help me to understand the Key Points that we need to remember while starting with WiX Installer. This article will help you to understand the important points that should be know are getting started with WiX. Windows Installer XML (WiX) is a toolset that builds Windows installation packages(MSI) from XML source code

Background

1. Visual Studio( can do away with this as well as WiX only need Microsoft .Net Framework to be installed, which is now default with Windows OS).

2. WiX Toolset, I have used v3.8.

Pros and Cons of using WiX

Pros

  • Free (Open Source)
  • Extention to UI, SQL, IIS and Powershell
  • Source control friendly

Cons

  • Steep Learning Curve
  • Difficult to find online resource
  • Only Support Windows Platform

Lets get started with an Example

Once your are done with the installation of WiS Toolset. Go to Visual Studio

New -> Project ->Click on WindowsInstallerXml and select Setup Project  and Click OK

The project will open Product.wxs file which would look like as below

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="WiXSample" Language="1033" Version="1.0.0.0" Manufacturer="Licence Owner" UpgradeCode="58f6b0f7-2894-4c62-9972-48b93f8332d9">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

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

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="WiXSample" />
            </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>

 

In the attached example I am creating a package which will install the application( Windows app to create GUID) and create an desktop shortcut for it.

Please find below the code from Product.wxs file along with the comments

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="GenerateGUID" Language="1033" Version="1.0.0.0" Manufacturer="Mohit Johri" 
           UpgradeCode="c7511d97-5e55-4eea-bab3-eebdf687b571">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    <!--The code is used to give Installation rights to the Admininstrator-->
    <Condition Message="You should have admin rights to install this application">
      Privileged
    </Condition>

        <MajorUpgrade DowngradeErrorMessage="A newer version of Generate GUID is already installed." />
        <MediaTemplate EmbedCab="yes" />
    <!--Directory Structure
        Source Directory where your .exe is been kept
        ProgramFilesFolder(Program Files) is the Directory where the Application will be installed
        GUID folder will be created while installing
    -->
    <!--Component is the atomic unit of things to be installed, in this case it the GenerateGUID.exe -->
    <Directory Id="TARGETDIR" Name="SourceDir">
         <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLDIR" Name="GUID">
               <Component Id="InstallFile" Guid="E841C739-934A-4B03-B623-A0814D7F651E">
                  <File Id="GenerateGUID" Source="GenerateGUID.exe" KeyPath="yes">
                    <Shortcut Id="desktopGuid" Directory="DesktopFolder" Name="Generate GUID" 
                              WorkingDirectory='INSTALLDIR' Icon="guid.ico" IconIndex="0" Advertise="yes" />
                  </File>
               </Component>
            
            </Directory>
         </Directory>
     <Directory Id="DesktopFolder" Name="Desktop" />
    </Directory>
    
    <!--we tell the installer what features we would like to install-->
        <Feature Id="ProductFeature"  Level="1">
            <ComponentRef Id="InstallFile" />
        </Feature>
    <Icon Id="guid.ico" SourceFile="guid.ico"/>
    
  <!--WixUI_Advanced
    WixUI_FeatureTree
    WixUI_InstallDir
    WixUI_Minimal
    WixUI_Mondo-->
    <UIRef Id="WixUI_Minimal"/>
    </Product>

</Wix>

 

Once the above application is build the .MSI can be found in the bin folder of the application.

Once the application is installed in can be seen on the Program Files and a desktop shortcut will also be created for the same.

To uninstall the application go to

Control Panel --> Programs and Features --> Select "GenerateGUID" and click on Uninstall button.

This will remove the application.

Key Points to remember

Product

  • Id needs to be change with each new version. Use Id="*", so that it will be automatically changed
  • Upgarde code needs to stay the same between different version

Package

  • InstallScope="perUser" by default, if it is not set. So this needs to changed to "perMachine" so that single machine should have same version and avoid redundancy

MediaTemplate

  • EmbedCab needs to be set to "yes" to embed the resources in the .msi file, else the project will generate a seperate .cab file and .msi file.

WixUIExtension

  • Add a reference to WiXUIExtension.dll ( Comes along with WiX toolset)
  • Add <UIRef Id="WixUI_Minimal"/> to product code ( as can be seen in the above example)

Component and File

  • Use a descriptive Name for the Id ( helps while you have n number of Component)
  • Use one File node per Component.
  • Set KeyPath="yes" for files which need to be restored ( In case you are re-installing the package in case of any error during installation)

External Links

 WiX Tutorial will give you the detailed descriprion about the WiX.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
Software Engineer, Loves cooking Indian food & Going for long drives

Comments and Discussions

 
-- There are no messages in this forum --