Windows Installer (WiX) Examples
Let me show some samples of the WiX usage that will show the simplicity and power of this wonderful product.
To get a full view of the topic sees the first post about the 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” />
</Component>
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:
<Component>
<user:User Id=’NewUser’ Name=’username’ Password=’password’ />
</Component>
While assembling the setup package it is necessary to link it with one of the extension modules:
light.exe –ext WixUtilExtension -out Sample.msi Sample.wixobj
This library allows the creation of common folders and the 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’ >
</user:FileShare>
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’ />
</Component>
</Directory>
</Directory>
</Directory>
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’ />
</WebVirtualDir>
</Component>
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’ />
</WebSite>
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
The WiX allows you to create the SQL database rather simply. We need to take some simple steps.
At the begging we include the required namespaces:
<Wix xmlns=’http://schemas.microsoft.com/wix/2006/wi’
xmlns:util=’http://schemas.microsoft.com/wix/UtilExtension
xmlns:sql=’http://schemas.microsoft.com/wix/SqlExtension>
Create the user:
<util:User Id=’SQLUser’ Name=’[SQLUSER]’ Password=’SQLPASSWORD’ />
I do the following step to create the component including all the required scripts, but 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’ />
</sql:SqlDatabase>
</Component>
Then we include the files with the sql-scripts to the project:
<Binary Id=’CreateTable’ SourceFile=’CreateTable.sql’ />
The file can contain the following:
CREATE TABLE Test (Value1 CHAR(50), Value2 INTEGER)
CREATE INDEX TestIndex ON Test (Value1)
Likewise, 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’ />
and
<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=’http://schemas.microsoft.com/wix/2006/wi’>
<Patch AllowRemoval=’yes’ Manufacturer=’Acme Ltd.’ MoreInfoURL=’www.acmefoobar.com’
DisplayName=’Foobar 1.0.1 Patch’ Description=’Small Update Patch’ Classification=’Update’>
<Media Id=’5000′ Cabinet=’Sample.cab’>
<PatchBaseline Id=’Sample’ />
</Media>
<PatchFamily Id=’SamplePatchFamily’ Version=’1.0.0.0′ Supersede=’yes’>
<ComponentRef Id=’MainExecutable’ />
</PatchFamily>
</Patch>
</Wix>
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
As well. 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.