Windows Installer (WiX) Examples

29 December 2010

In this part I’d like to show some samples of the WiX usage that will demonstrate simplicity and power of this wonderful product.

To get the full view of the topic see the first post about WiX.

We’ll have to accomplish the following tasks:

Setup the .NET-assembly in GAC
Creation of New Users and Rights Distribution
Creation of the Virtual Catalogue in IIS
SQL Database Creation
Patch Creation

Setup the .NET-assembly in GAC

To add the assembly to GAC you need to make one simple move: set up tag attributes for the Assembly and AssemblyManifest File tag, but don’t point down the AssemblyApplication tag.

<Component Id=”SomeFile” Guid=”…” DiskId=”1″>

<File Name=”SomeFile.dll” KeyPath=”yes” src=”C:\SomeFile.dll” Checksum=”yes”

Assembly=”.net” AssemblyManifest=”SomeFile.dll” />


Creation of New Users and Rights Distribution

The WiX toolset contains additional libraries that let you add new users to the target machine.
To do this you need to define in its components:


<user:User Id=’NewUser’ Name=’username’ Password=’password’ />


While assembling the setup package it is necessary to link it with the one of the extension modules:

light.exe –ext WixUtilExtension -out Sample.msi Sample.wixobj

Also this library allows creation of common folders and distribution of rights.

For example, the following code will find the user with the name Everyone and will define the rights for the common folder:

<user:User Id=’Everyone’ Name=’Everyone’ CreateUser=’no’

FailIfExists=’no’ RemoveOnUninstall=’no’ />

<user:FileShare Id=’MainExecutableShare’ Description=’Foobar 1.0 share’ Name=’FoobarShare’>

<user:Permission GenericRead=’yes’ ReadPermission=’yes’ Read=’yes’

GenericExecute=’yes’ User=’Everyone’ >


Creation of the Virtual Catalogue in IIS

The WiX toolset contains additional libraries that let users create the virtual catalogue within setup process. To resolve this uneasy task you need to take the following simple steps:

<Directory Id=’TARGETDIR’ Name=’SourceDir’>

<Directory Id=’ProgramFilesFolder’ Name=’PFiles’>

<Directory Id=’InstallDir’ Name=’Acme’>

<Component Id=’default.phpComponent’ Guid=’YOURGUID’>

<File Id=’default.htmFile’ Name=’default.htm’ Source=’default.htm’

DiskId=’1’ KeyPath=’yes’ />





Then we make the virtual catalogue:

<Component Id=’TestWebVirtualDirComponent’ Guid=’YOURGUID’>

<WebVirtualDir Id=’TestWebVirtualDir’ Alias=’Test’ Directory=’InstallDir’ WebSite=’DefaultWebSite’>

<WebApplication Id=’TestWebApplication’ Name=’Test’ />



The following step is creation of the record to link to the website:

<WebSite Id=’DefaultWebSite’ Desciption=’Default Web Site’>

<WebAddress Id=’AllUnassigned’ Port=’80’ />


Then we create the required setup package linking it to the appropriate WiX library:

light.exe -out SampleWebDir.msi SampleWebDir.wixobj path\sca.wixlib

SQL Database Creation

WiX allows you to create the SQL database in a rather simple way. We need to take some simple steps.

First we include the required namespaces:

<Wix xmlns=’’



Create the user:

<util:User Id=’SQLUser’ Name=’[SQLUSER]’ Password=’SQLPASSWORD’ />

The following step is done to create the component including all the required scripts. Also we determine the order and time to run these scripts and the actions to perform in case of unexpected situations (for example, if the database already exists).

<Component Id=’SqlComponent’ Guid=’YOURGUID’>

<sql:SqlDatabase Id=’SqlDatabase’ Database=’Foobar’ User=’SQLUser’ Server=’[SQLSERVER]’

CreateOnInstall=’yes’ DropOnUninstall=’yes’ ContinueOnError=’yes’>

<sql:SqlScript Id=’CreateTable’ BinaryKey=’CreateTable’ ExecuteOnInstall=’yes’ />



Then we include the files with the sql-scripts to the project:

<Binary Id=’CreateTable’ SourceFile=’CreateTable.sql’ />

File can contain the following:

CREATE TABLE Test (Value1 CHAR(50), Value2 INTEGER)

CREATE INDEX TestIndex ON Test (Value1)

And we assemble the package, but don’t forget to link it with the appropriate WiX modules:

candle.exe -ext WixUtilExtension -ext WixSqlExtension SampleSQL.wxs
light.exe -ext WixUtilExtension -ext WixSqlExtension SampleSQL.wixobj

Patch Creation

The WiX toolset allows creating patches and updating the product on the target machine. Again patch creation doesn’t require many efforts. We need two setup packages to create a patch: the old one with the error and the new one with the fixed error.

For example, let’s assume we have two packages with names Error.wxs and Fixed.wxs that differ only in the source of some file.

<File Id=’FoobarEXE’ Name=’FoobarAppl10.exe’ DiskId=’1’

Source=’Error\FoobarAppl10.exe’ KeyPath=’yes’ />


<File Id=’FoobarEXE’ Name=’FoobarAppl10.exe’ DiskId=’1’

Source=’Fixed\FoobarAppl10.exe’ KeyPath=’yes’ />

The patch itself will be created from the third source. It is the particular XML file.

<?xml version=’1.0′ encoding=’windows-1252′?>

<Wix xmlns=’’>

<Patch AllowRemoval=’yes’ Manufacturer=’Acme Ltd.’ MoreInfoURL=’’

DisplayName=’Foobar 1.0.1 Patch’ Description=’Small Update Patch’ Classification=’Update’>

<Media Id=’5000′ Cabinet=’’>

<PatchBaseline Id=’Sample’ />


<PatchFamily Id=’SamplePatchFamily’ Version=’′ Supersede=’yes’>

<ComponentRef Id=’MainExecutable’ />




Here you define the patch type (attribute Classification), if the deinstallation is possible (attribute AllowRemoval), etc.
The next move is to build two basis setup packages with the following commands in the command line:

candle.exe Error.wxs

light.exe -out Error\Product.msi Error.wixobj

candle.exe Fixed.wxs

light.exe -out Fixed\Product.msi Fixed.wixobj

Also we need to create our fixes package with the ordinary compiler and WiX linker:

candle.exe Patch.wxs
light.exe Patch.wixobj

And the last thing to do is to build the patch itself by using the special tool WiX:

pyro.exe Patch.wixmsp -out Patch.msp -t Sample Patch.wixmst

As a result we get the patch with the name Patch.msp.