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.
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 (
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.
- Create a .WXS file. This is the XML file that is the script for your WIX installation.
candle.exe YOUR PROJECT NAME.wxsto compile a
YOUR PROJECT NAME.wixobj.
light.exe YOUR PROJECT NAME.wixobjto compile a
YOUR PROJECT NAME.msi.
That sounds fairly straightforward, and it is, until you've seen your first
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.
- The file has a root element
Wix. Nothing surprising there.
- You define a
Product. That also makes sense. The first thing you notice is this line:For some reason somebody at Microsoft thought it a bright idea to sprinkle everything with GUID.s Be warned, you'll need tons of GUIDs for a .WXS file, and they all need to be unique. This is why reasonable people create the GUIDs in a script (for exaple in Python, using uuid.uuid4()).
YET ANOTHER GUID GOES HERE
- For a full list of
Productoptions, see the Product Element Description
- Then you need a
Package. Again, tons of attributes, described here
- And then, in a bow to the early days of computing, you must add a definition of how to handle
your MSI script on installation media such as floppy disk (or CD ROM). I know, it sounds like a joke: if only it were.
At any rate, the two lines above for
Propertytake care of FLOPPY DISK INSTALLATION. Fat chance!