Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WiX: A Developer's Guide to Windows Installer XML

You're reading from   WiX: A Developer's Guide to Windows Installer XML If you‚Äôre a developer needing to create installers for Microsoft Windows, then this book is essential. It‚Äôs a step-by-step tutorial that teaches you all you need to know about WiX: the professional way to produce a Windows installer package.

Arrow left icon
Product type Paperback
Published in Oct 2010
Publisher Packt
ISBN-13 9781849513722
Length 348 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (18) Chapters Close

WiX: A Developer's Guide to Windows Installer XML
Credits
About the Author
About the Reviewer
Preface
1. Getting Started FREE CHAPTER 2. Creating Files and Directories 3. Putting Properties and AppSearch to Work 4. Improving Control with Launch Conditions and Installed States 5. Understanding the Installation Sequence 6. Adding a User Interface 7. Using UI Controls 8. Tapping into Control Events 9. Working from the Command Line 10. Accessing the Windows Registry 11. Controlling Windows Services 12. Localizing Your Installer 13. Upgrading and Patching

Introducing Windows Installer XML


In this section, we'll dive right in and talk about what WiX is, where to get it, and why you'd want to use it when building an installation package for your software. We'll follow up with a quick description of the WiX tools and the new project types made available in Visual Studio.

What is WiX?

Although it's the standard technology and has been around for years, creating a Windows Installer, or MSI package, has always been a challenging task. The package is actually a relational database that describes how the various components of an application should be unpacked and copied to the end user's computer.

In the past you had two options:

  • You could try to author the database yourself—a path that requires a thorough knowledge of the Windows Installer API.

  • You could buy a commercial product like InstallShield to do it for you. These software products will take care of the details, but you'll forever be dependent on them. There will always be parts of the process that are hidden from you.

WiX is relatively new to the scene, offering a route that exists somewhere in the middle. Abstracting away the low-level function calls while still allowing you to write much of the code by hand, WiX is an architecture for building an installer in ways that mere mortals can grasp. Best of all, it's free. As an open source product, it has quickly garnered a wide user base and a dedicated community of developers. Much of this has to do not only with its price tag but also with its simplicity. It can be authored in a simple text editor (such as Notepad) and compiled with the tools provided by WiX. As it's a flavor of XML, it can be read by humans, edited without expensive software, and lends itself to being stored in source control where it can be easily merged and compared.

The examples in this first chapter will show how to create a simple installer with WiX using Visual Studio. However, later chapters will show how you can build your project from the command line using the compiler and linker from the WiX toolset. The WiX source code is available for download, so you can be assured that nothing about the process will be hidden if you truly need to know.

Is WiX for you?

To answer the question "Is WiX for you?" we have to answer "What can WiX do for you?" It's fairly simple to copy files to an end user's computer. If that's all your product needs, then the Windows Installer technology might be overkill. However, there are many benefits to creating an installable package for your customers, some of which might be overlooked. Following is a list of features that you get when you author a Windows Installer package with WiX:

  • All of your executable files can be packaged into one convenient bundle, simplifying deployment.

  • Your software is automatically registered with Add/Remove Programs.

  • Windows takes care of uninstalling all of the components that make up your product when the user chooses to do so.

  • If files for your software are accidently removed, they can be replaced by right-clicking on the MSI file and selecting Repair.

  • You can create different versions of your installer and detect which version has been installed.

  • You can create patches to update only specific areas of your application.

  • If something goes wrong while installing your software, the end user's computer can be rolled back to a previous state.

  • You can create Wizard-style dialogs to guide the user through the installation.

Many people today simply expect that your installer will have these features. Not having them could be seen as a real deficit. For example, what is a user supposed to do when they want to uninstall your product but can't find it in the Add/Remove Programs list and there isn't an uninstall shortcut? They're likely to remove files haphazardly and wonder why you didn't make things easy for them.

Maybe you've already figured that Windows Installer is the way to go, but why WiX? One of my favorite reasons is that it gives you greater control over how things work. You get a much finer level of control over the development process. Commercial software that does this for you also produces an MSI file, but hides the details about how it was done. It's analogous to crafting a web site. You get much more control when you write the HTML yourself as opposed to using WYSIWYG software.

Even though WiX gives you more control, it doesn't make things overly complex. You'll find that making a simple installer is very straightforward. For more complex projects, the parts can be split up into multiple XML source files to make it easier to work with. Going further, if your product is made up of multiple products that will be installed together as a suite, you can compile the different chunks into libraries that can be merged together into a single MSI. This allows each team to isolate and manage their part of the installation package.

WiX is a stable technology, having been first released to the public in 2004, so you don't have to worry about it disappearing. It's also had a steady progression of version releases. The most current version is updated for Windows Installer 4.5 and the next release will include changes for Windows Installer 5.0, which is the version that comes preinstalled with Windows 7. These are just some of the reasons why you might choose to use WiX.

Where can I get it?

You can download WiX from the Codeplex site, http://wix.codeplex.com/, which has both stable releases and source code. The current release is version 3.0. Once you've downloaded the WiX installer package, double-click it to install it to your local hard drive.

This installs all of the necessary files needed to build WiX projects. You'll also get the WiX SDK documentation and the settings for Visual Studio IntelliSense, highlighting and project templates. Version 3 supports Visual Studio 2005 and Visual Studio 2008, Standard edition or higher.

WiX comes with the following tools:

Tool

What it does

Candle.exe

Compiles WiX source files (.wxs) into intermediate object files (.wixobj).

Light.exe

Links and binds .wixobj files to create final .msi file. Also creates cabinet files and embeds streams in MSI database.

Lit.exe

Creates WiX libraries (.wixlib) that can be linked together by Light.

Dark.exe

Decompiles an MSI file into WiX code.

Heat.exe

Creates a WiX source file that specifies components from various inputs.

Melt.exe

Converts a "merge module" (.msm) into a component group in a WiX source file.

Torch.exe

Generates a transform file used to create a software patch.

Smoke.exe

Runs validation checks on an MSI or MSM file.

Pyro.exe

Creates an patch file (.msp) from .wixmsp and .wixmst files.

WixCop.exe

Converts version 2 WiX files to version 3.

In order to use some of the functionality in WiX, you may need to download a more recent version of Windows Installer. You can check your current version by viewing the help file for msiexec.exe, which is the Windows Installer service. Go to your Start Menu and select Run, type cmd and then type msiexec /? at the prompt. This should bring up a window like the following:

If you'd like to install a newer version of Windows Installer, you can get one from the Microsoft Download Center website. Go to:

http://www.microsoft.com/downloads/en/default.aspx

Search for Windows Installer. The current version for Windows XP, Vista, Server 2003, and Server 2008 is 4.5. Windows 7 and Windows Server 2008 R2 can support version 5.0. Each new version is backwards compatible and includes the features from earlier editions.

Votive

The WiX toolset provides files that update Visual Studio to provide new WiX IntelliSense, syntax highlighting, and project templates. Together these features, which are installed for you along with the other WiX tools, are called Votive. You must have Visual Studio 2005 or 2008 (Standard edition or higher). Votive won't work on the Express versions. If you're using Visual Studio 2005, you may need to install an additional component called ProjectAggregator2. Refer to the WiX site for more information:

http://wix.sourceforge.net/votive.html

After you've installed WiX, you should see a new category of project types in Visual Studio, labeled under the title WiX. To test it out, open Visual Studio and go to File | New | Project. Select the category WiX.

There are six new project templates:

  • WiX Project: Creates a Windows Installer package from one or more WiX source files

  • WiX Library Project: Creates a .wixlib library

  • C# Custom Action Project: Creates a .NET custom action in C#

  • WiX Merge Module Project: Creates a merge module

  • C++ Custom Action Project: Creates an unmanaged C++ custom action

  • VB Custom Action Project: Creates a VB.NET custom action

Using these templates is certainly easier than creating them on your own with a text editor. To start creating your own MSI installer, select the template WiX Project. This will create a new .wxs (WiX source file) for you to add XML markup to. Once we've added the necessary markup, you'll be able to build the solution by selecting Build Solution from the Build menu or by right-clicking on the project in the Solution Explorer and selecting Build. Visual Studio will take care of calling candle.exe and light.exe to compile and link your project files.

If you right-click on your WiX project in the Solution Explorer and select Properties, you'll see several screens where you can tweak the build process. One thing you'll want to do is set the amount of information that you'd like to see when compiling and linking the project and how non-critical messages are treated. Refer to the following screenshot:

Here, we're selecting the level of messages that we'd like to see. To see all warnings and messages, set the Warning Level to Pedantic. You can also check the Verbose output checkbox to get even more information. Checking Treat warnings as errors will cause warning messages that normally would not stop the build to be treated as fatal errors.

You can also choose to suppress certain warnings. You'll need to know the specific warning message number, though. If you get a build-time warning, you'll see the warning message, but not the number. One way to get it is to open the WiX source code (available at http://wix.codeplex.com/SourceControl/list/changesets) and view the messages.xml file in the Wix solution. Search the file for the warning and from there you'll see its number. Note that you can suppress warnings but not errors.

Another feature of WiX is its ability to run validity checks on the MSI package. Windows Installer uses a suite of tests called Internal Consistency Evaluators (ICEs) for this. These checks ensure that the database as a whole makes sense and that the keys on each table join correctly. Through Votive, you can choose to suppress specific ICE tests. Use the Tools Setting page of the project's properties as shown in the following screenshot:

In this example, ICE test 102 is being suppressed. You can specify more than one test by separating them with semicolons. To find a full list of ICE tests, go to MSDN's ICE Reference web page at:

http://msdn.microsoft.com/en-us/library/aa369206%28VS.85%29.aspx

The Tool Settings screen also gives you the ability to add compiler or linker command-line flags. Simply add them to the text boxes at the bottom of the screen. We will discuss command-line arguments for Candle and Light later in the book.

A word about GUIDs

In various places throughout WiX, you'll be asked to provide a GUID, which is a Globally Unique Identifier. This is so that when your product is installed on the end user's computer, references to it can be stored in the Windows Registry without the chance of having name conflicts. By using GUIDs, Windows Installer can be sure that every software application, and even every component of that software, has a unique identity on the system.

Each GUID that you create on your computer is guaranteed to be different from a GUID that someone else would make. Using this, even if two pieces of software, both called "Amazing Software", are installed on the same computer, Windows will be able to tell them apart.

Visual Studio 2008 provides a way to create a GUID. Go to Tools | Create GUID and copy a new GUID using the Registry Format. WiX can accept a GUID with or without curly brackets around it as 01234567-89AB-CDEF-0123-456789ABCDEF or {01234567-89AB-CDEF-0123-456789ABCDEF}.

Be sure to only use uppercase letters, though. In this book, I'll display real GUIDs, but you should not reuse them as then your components will not be guaranteed to be unique.

You have been reading a chapter from
WiX: A Developer's Guide to Windows Installer XML
Published in: Oct 2010
Publisher: Packt
ISBN-13: 9781849513722
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image