WiX for the impatient

At work, our main product is typically installed using the very fine NSIS installer setup. However, today I had to write an .MSI script for a specific customer, and choose the WIX toolset to do so. I had to google a bit to get it all fixed up together, so I decided to write it down for future reference; maybe it will be helpful for you, too.

Overview

The Windows Installer is to software installation, what Visual Sourcesafe is to version control.

That being said, sometimes you have to accept your fate and write an .MSI. You can choose expensive software, or just take a free option: and the WIX toolset seems to be the most widely used one at that.

WiX is based on an XML script that describes the installation. The XML script is then "compiled" using two separate tools (candle.exe and light.exe). It is probably only fair to say that some of the quirks of using WiX are actually the quirks of using MSI, so don't blame the messenger (WiX, as it were).

MSI is a "database" of "components" that, together, make up your installation. It can do great things like ... installing software, and - gasp! - uninstalling it! I can hardly contain my excitement... It is crucial to understand that this is completely diametrically opposed to the logic of normal installers such as NSIS. NSIS uses a script that has instructions that are executed sequentially, which to a programmer makes a lot of sense, because you expect your installation to proceed sequentially. MSI uses its "database" to "ensure" everything is in place. The "benefit" of that approach is that you don't need to program. Now, I started programming 30 years ago and up until today I have not often felt that "you don't need to program" is desirable in some form, but that is probably just me...

And the drawback: well, just google for "msi problems" and you'll see the drawback...

The basic workflow

Oh, apparently you can integrate WiX in Visual Studio, but here at p-nand-q.com we're hardcore, so we'll do the install with scripts, from the command line, like the good old-school programmers we are.

That sounds fairly straightforward, and it is, until you've seen your first .WXS file.

Anatomy of a .WXS file

Remember, a .WXS file is an XML file. Fire up your favourite editor and start typing:

<?xml version='1.0' encoding='utf-8'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>

    <Product Name='SUPER FINE INSTALLER' 
        Id='YET ANOTHER GUID GOES HERE' 
        UpgradeCode='YET ANOTHER GUID GOES HERE
        Language='1031' Codepage='1252' Version='1.0.0'
        Manufacturer='ACME SUPERCORP'>

        <Package Id='*' Keywords='Installer' Description="ACME SUPERCORP RULES"
          Comments='ACME SUPERCORP IS BEST CORP' 
          Manufacturer='ACME SUPERCORP'
          InstallerVersion='100' Languages='1031' Compressed='yes' SummaryCodepage='1252' />
      
        <Media Id='1' Cabinet='Sample.cab' EmbedCab='yes' DiskPrompt='CD-ROM #1' />
        <Property Id='DiskPrompt' Value="ACME SUPERCORP FLOPPY DISK #1/9999" />  

        ...
    </Product>
</Wix>

Whoa whoa whoa. That's a lot of stuff right here, let's dissect that one by one.

So, what do you actually install? Well, how about files, services and the registry?