Windows Installer XML (WiX)
What is Windows Installer XML (WiX) and why to use it if there are so many other tools available? Is it really that good?
Majority of the developers already had a deal with the Microsoft Office 2007 or Visual Studio 2010 setups. They saw appealing interface and clear settings. Although it’s not a common knowledge that the setups of these complex products are written in a little-known Windows Installer XML (WiX).
Nowadays Microsoft is using WiX for the setups of its software products. And I believe the Microsoft origin of WiX isn’t the only reason.
Let ‘s get some insight into WiX to understand why it’s happening.
• What is WiX
• Why Not to Use Instead of WiX …
• WiX Benefits for .NET
• Sample XML File and WiX
• WiX Usage Examples
Windows Installer XML (WiX) is the toolset with the open source that let you build the Windows Installer packages out of XML descriptions. WiX was the first Microsoft product to be developed on the SourceForge platform and to be distributed under open license CPL.
The WiX includes a number of the console utilities to provide the comprehensive work with the setup packages creation. Additional tools let you use WiX within the integrated development environments such as Microsoft Visual Studio or SharpDevelop.
Download WiX from SourceForge:
• WiX 2.0 + Votive2 (VisualStudio 2005)
• WiX 3.0 + Votive 3 (VisualStudio 2008/2010)
There you can download the beta version of the WiX 3.5. Also track the weekly releases.
Further reading about WiX:
• WiX Tutorial from Gabor DEAK JAHN — great introduction to WiX with examples.
• wix.sourceforge.net — website of the WiX projects containing main sources and docs.
We won’t tutor the syntax and different ways to use WiX. You can find it in official docs of the project or other Internet sources.
We’ll try to answer the question why the usage of WiX is a better choice in comparison with the other ways to create the setup packages and deploy them on the target client machine.
Your own script or installer? After deployment you apparently will get something with the set of the functionality that is the subset of the staff WiX already can create for you and create it in more reliable way. The definition of the setup process in the terms of the Windows Installer let the OS and other tools to run the process smarter, for example, to determine that the common components are installed correctly and updated or to display you product in the Programs and Features list.
WiX usage will get all the benefits of Windows Installer for you.
Orca utility or API? This approach let you edit MSI package directly. Remember that its format is for the Windows Installer not the developers. WiX makes the setup writing much easier and automatically generates setup packages. Besides WiX expands the basic capabilities of the Windows Installer, e.g. you get the opportunity to create and setup the website or Database on SQL Server.
Visual Studio Installer? Visual Studio has the built-in project type for the MSI-packages creation but it’s useful only for simplest cases. Particularly it has only one “feature”, very limited in the settings and doesn’t support updates. Also it leans significantly on programming of the setup process with the .NET installer classes. If the integration with the Visual Studio is important for you than use Votive.
InstallShield / Wise / etc.? There is a set of the commercial products simplifying the Windows Installer packages creation. They are helpful if you just begin to learn the installation process and you need a user-friendly interface to lead you through. But the majority of the developers working with the installation packages come to understanding that it’s better to use the tool working in the data model of the Windows Installer applying all its capabilities. And WiX has an open source and it’s free!
XCOPY? If you can distribute you product by simple coping then do it (WiX is distributed in this exact way). But for majority of the products – especially those requiring the server installation or other products integration setup isn’t just XCOPY.
And all the above I’d like to name the WiX features important for the .NET.
• WiX Tools work under .NET. You should install .NET Framework 1.1 and package SP1 to use WiX utilities.
• .NET Framework is required only for the WiX and the ready-made package doesn’t require it on the target machine.
• Starting with the WiX 3.5 version the setup can automatically install the required version of the .NET Framework on the target machine.
• The user actions for the non-standard setup tasks can be written on any programming language of the .NET Framework or С++.
Also I’d like to add that WiX uses declarative language not the procedural one that means you describe how the set up product will look like not the stages to reach the goal. It can be unusual at first but it’s easy to learn.
After brief description of the features and benefits of WiX we can give the example of the sample XML-file. This file despite its simplicity turns out into full setup package with dialog windows and logical actions after compiling.
<Wix xmlns=”http://schemas.microsoft.com/wix/2006/wi”>
<?define ProductName=”SetupProject1″ ?>
<?define ProductVersion=”1.0.0.0″ ?>
<?define ProductCode=”b7bc7c6f-9a4e-4973-be84-eca8e3427c97″?>
<?define UpgradeCode=”06a81104-1e30-463d-87e1-e8a79b4c682a”?>
<?define Manufacturer=”MyCompany”?>
<Product Id=”$(var.ProductCode)” Language=”1049″ Version=”$(var.ProductVersion)”
Manufacturer=”$(var.Manufacturer)” UpgradeCode=”$(var.UpgradeCode)”>
<Package InstallerVersion=”200″ Compressed=”yes” />
<Media Cabinet=”media1.cab” EmbedCab=”yes” />
<Directory Name=”SourceDir”>
<Directory Id=”ProgramFilesFolder”>
<Directory Name=”$(var.ProductName)”>
<Component Id=”ProductComponent” Guid=”b11556a2-e066-4393-af5c-9c9210187eb2″>
<File Id=’Calc’ DiskId=’1′ Source=’C:\WINDOWS\system32\calc.exe’/>
</Component>
</Directory>
</Directory>
<Directory Id=”ProgramMenuFolder”>
<Directory Id=”ApplicationProgramsFolder” Name=”$(var.ProductName)”>
<Component Guid=”4CEBD68F-E933-47f9-B02C-A4FC69FDB551″>
<Shortcut Id=”ShortcutCalc” Description=”$(var.ProductName)”
Target=”[INSTALLLOCATION]Calc.exe” WorkingDirectory=”INSTALLLOCATION”/>
<RemoveFolder Id=”ApplicationProgramsFolder” On=”uninstall”/>
<RegistryValue Root=”HKCU” Key=”Software\$(var.Manufacturer)\$(var.ProductName)”
Name=”installed” Value=”1″ KeyPath=”yes”/>
</Component>
</Directory>
</Directory>
</Directory>
<Feature Title=”SetupProject1″ Level=”1″>
<ComponentRef />
<ComponentRef />
</Feature>
<Property Id=”WIXUI_INSTALLDIR” Value=”INSTALLLOCATION” ></Property>
<WixVariable Id=”WixUILicenseRtf” Overridable=”yes” Value=”License.rtf”/>
<UIRef Id=”WixUI_InstallDir”/>
</Product>
</Wix>
The file like the one above gives you the setup package that performs a lot of work:
– Shows several dialog windows (welcome, licence agreement, directory browsing, and setup dialog windows)
– Adds the calc.exe file to the picked directory
– Adds the folder and icon to the Start Menu
– Adds the key to the register
– Deletes the folder with the “program” form the Start Menu after uninstalling
And who could guess ….
Look for WiX examples in the second post about Windows Installer.
Got a question? Drop us a line below and .NET Development Department will answer.
Leave a Comment