Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
WiX: A Developer's Guide to Windows Installer XML
WiX: A Developer's Guide to Windows Installer XML

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.

eBook
$9.99 $32.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

WiX: A Developer's Guide to Windows Installer XML

Chapter 2. Creating Files and Directories

In the previous chapter, we saw that creating a WiX installer isn't so tough. Less than seventy lines of code and you've got a professional-looking deployment solution. One of the things we covered was how to copy files and create directories on the end user's computer. We've covered the basics, but now it's time to dig deeper.

In this chapter you will learn how to:

  • Organize your File and Directory elements using DirectoryRef and ComponentGroup elements

  • Split your WiX markup using Fragment elements to keep it manageable

  • Use heat.exe to create Component markup

  • Install special case files such as installing to the GAC

File element


The File element, as you've seen, is used to designate each file that you plan to copy to the end user's computer. Its Source attribute tells WiX where to find the file on your local machine. The Name attribute tells the installer what the file will be called after it's installed. Each File element also needs an Id. This uniquely identifies it in the MSI database's File table.

<Component Id="CMP_MyProgramEXE"
           Guid="E8A58B7B-F031-4548-9BDD-7A6796C8460D">
  <File Id="FILE_MyProgramEXE"
        Source="MyProgram.exe" 
        Name="NewName.exe" 
        KeyPath="yes" />
</Component>

<Component Id="CMP_AnotherFileDLL"
           Guid="E9D74961-DF9B-4130-8FBC-1669A6DD288E">
  <File Id="FILE_AnotherFileDLL" 
        Source="..\..\AnotherFile.dll"
        KeyPath="yes" />
</Component>

This example includes two files, MyProgram.exe and AnotherFile.dll, in the installation package. Both use relative paths for their Source attributes. The...

DirectoryRef element


In the previous chapter, you saw that to define which directories to copy your files into, you use Directory elements. These take an Id and, if it's a new directory that you're creating, a Name attribute. You can use any of the built-in IDs to reference one of the common Windows directories. For example, suppose we wanted to add a file to the C:\Windows\system32 folder. We'd add a reference to it using the built-in SystemFolder property for its Id:

<Directory Id="TARGETDIR"
           Name="SourceDir">
  <Directory Id="SystemFolder" />
</Directory>

If, on the other hand, it's a directory that you're creating, you can set the Id to anything you like. The Name attribute will set the name of the new folder. After you've defined the directories that you want to use (or create) with Directory elements, you'll use DirectoryRef elements to add components to them.

<DirectoryRef Id="SystemFolder">
  <Component Id="CMP_AnotherFileDLL" 
             Guid...

ComponentGroup element


The ComponentGroup element can be used to group Component elements, which is helpful as it offers a way to reference all of your components with a single element. For example, when adding components to a Feature (which you must always do), you could use ComponentRef elements directly. This is the technique we used in the previous chapter.

<Feature Id="ProductFeature"
         Title="Main Product"
         Level="1">
  <ComponentRef Id="CMP_MyProgramEXE" />
  <ComponentRef Id="CMP_AnotherFileDLL" />
</Feature>

However, by creating a ComponentGroup, you can reference multiple components with a single ComponentGroupRef element. This is shown in the snippet:

<Feature Id="ProductFeature"
         Title="Main Product"
         Level="1">
  <ComponentGroupRef Id="MyComponentGroup" />
</Feature>

To create a ComponentGroup, add a new CompontGroup element to your .wxs file. It can go anywhere inside the Product element. Then, you have a...

Fragment element


Up to this point, we've been adding all of our WiX elements to the Product.wxs file. When your installer packages hundreds of files, you'll find that having all of your code in one place makes reading it difficult. You can split your elements up into multiple .wxs files for better organization and readability. Whereas your main source file, Product.wxs, nests everything inside a Product element, your additional .wxs files will use Fragment elements as their roots.

The Fragment element doesn't need any attributes. It's simply a container. You can place just about anything inside of it, such as all of your Directory elements or all of your Component elements. For the next example, add a new WiX source file to your project and place the following markup inside it. Here, we're using the same ComponentGroup that we discussed earlier. You can call the file Components.wxs, and it would look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas...

Harvesting files with heat.exe


When your project contains many files to install, it can be a chore to create File and Component elements for all of them. Instead, WiX can do it for you. One of the tools that ships with the toolset is called heat.exe. You can find it in the bin directory of the WiX program files. Navigate to WiX's bin directory from a command prompt and type heat.exe -? to see information about its usage.

To make things easy, consider adding the path to the WiX bin directory to your computer's PATH environment variable so that you won't have to reference the full path to the executable each time you use it. You can do this by right-clicking on My Computer in your Start Menu and then going to Properties | Advanced | Environment Variables. From there, you can add the WiX bin path, C:\Program Files\Windows Installer XML v3\bin, to PATH by finding PATH in the list of System variables and clicking Edit.

Note

Note that WiX, during its installation, adds an environment variable called...

Copying and moving files


File and Component elements allow you to add new files to the end user's computer. However, WiX also provides ways to copy and move files. For these tasks, you'll use the CopyFile element. We'll discuss how to use it in the following sections.

Copying files you install

The CopyFile element can copy a file that you're installing and place it in another directory. You'll nest it inside the File element of the file you want to duplicate. First, we'll add a subdirectory to the MyProgramDir folder that we're already creating under Program Files. The new directory will be called Copied Files.

<Directory Id="TARGETDIR"
           Name="SourceDir">
  <Directory Id="ProgramFilesFolder">
    <Directory Id="MyProgramDir"
               Name="Awesome Software">
      <Directory Id="CopiedFiles"
                 Name="Copied Files" />
    </Directory>
  </Directory>
</Directory>

Now, we can nest a CopyFile element inside the File element...

Installing special-case files


In the following sections, we'll take a look at installing files that are different from other types that we've talked about so far. Specifically, we'll cover how to install an assembly file (.dll) to the Global Assembly Cache and how to install a TrueType font file.

Adding assembly files to the GAC

The Global Assembly Cache (GAC) is a central repository in Windows where you can store .NET assembly files so that they can be shared by multiple applications. You can add a .NET assembly to it with WiX by setting the File element's Assembly attribute to .net. The following example installs an assembly file to the GAC:

<DirectoryRef Id="MyProgramDir">
  <Component Id="CMP_MyAssembly" 
             Guid="4D98D593-F4E0-479B-A7DA-80BBB78B54CB">
    <File Id="File_MyAssembly"
          Assembly=".net" 
          Source="MyAssembly.dll"
          KeyPath="yes" />
  </Component>
</DirectoryRef>

Even though we've placed this component inside a...

Creating an empty folder


Ordinarily, Windows Installer won't let you create empty folders. However, there is a way: Use the CreateFolder element inside an otherwise empty Component element. First, you'll define the name of your empty directory with a Directory element. Follow this example:

<Directory Id="TARGETDIR"
           Name="SourceDir">
  <Directory Id="ProgramFilesFolder">
    <Directory Id="MyProgramDir"
               Name="Awesome Software">
      <Directory Id="MyEmptyDir"
                 Name="Empty Directory" />
    </Directory>
  </Directory>
</Directory>

Here, we've added a new Directory element named Empty Directory inside our main application folder. The next step is to add a component to this directory by using a DirectoryRef element. Notice that we've set the KeyPath attribute on the component to yes, as there will be no file to serve this purpose.

<DirectoryRef Id="MyEmptyDir">
  <Component Id="CMP_MyEmptyDir" 
     ...

Setting file permissions


WiX allows you to set the permissions that Windows users and groups have to the files that you install. You can see these permissions by right-clicking on a file and selecting the Security tab. On Windows XP, you may have to configure your system so that this tab is visible. In Windows Explorer, open the folder that you want to configure and go to Tools | Folder Options | View. Then, uncheck the box that says Use simple file sharing. Here's an example of the Security tab on a file:

To set the permissions for a file that you're installing, nest a PermissionEx element inside the corresponding File element. This element, which is available from the WixUtilExtension, has various attributes that can be used to define file permissions. Before you can use it, you'll need to add a reference to WixUtilExtension.dll in your project. Go to Add Reference in the Solution Explorer, navigate to the WiX bin directory, and select the assembly. Next, add the following namespace to...

Speeding up file installations


We haven't talked too much about how the files and directories that you author in your WiX source files are stored in the MSI database's tables. The files are stored in a table called File, the directories in a table called Directory, and the components in a table called Component. You can see this by opening the MSI package with Orca.exe.

In the following example, I have four files that are being installed. I've used the convention of prefixing my file IDs with "FILE_", giving me FILE_InstallMeTXT, for example.

Each file in the File table is sorted alphabetically by the Id you gave to it via the File element. This is the order in which the files are copied to the end user's computer. So, how can you make things faster? You can give your files IDs that will cause WiX to sort them more efficiently.

The file copy process takes longer when Windows has to write to one directory and then switch to another and then another and so on. If it could copy all of the files...

Summary


In this chapter, we discussed the elements used to install files and create directories. The File, Directory and Component elements play vital roles here, but you may also benefit from using ComponentGroup to group your components. This allows you to better organize your markup and even to separate it into multiple WiX source files.

The heat.exe tool can create Component elements for you. You simply need to point it at a certain directory. However, it's best to fine-tune its arguments so that the output that you get is optimal. We discussed a few other topics such as how to copy a file, how to set file permissions and how to organize your File element Id attributes for maximum installation speed.

In the next chapter, we'll move on to discuss WiX properties and the various ways of searching the end user's system for files, directories, and settings.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Package your software into a single-file, double-click MSI for easy installation
  • Read and write to the Windows Registry and create, start, and stop Windows Services during installation
  • Write .NET code that performs specific tasks during installation via custom actions
  • Learn how the WiX command-line tools work to build and link your project
  • Become proficient with to-the-point examples and real-world advice

Description

WiX is an open source project and a toolset that builds Windows installation packages from XML source code. WiX, which is used internally by Microsoft and by many companies around the World, simplifies many of the installation tasks that used to be shrouded in mystery. The tool set provides a command-line environment that you can integrate into your old-style build processes or you can use the newer technology from inside integrated development environments to build your setup packages. You'll find that you understand your installer better, can create it in less time, and save money in the process. No one really wants to devote a lifetime to understanding how to create a hassle-free installer for any software. This hands-on guide takes the mystery out of Windows Installer by showing how simple XML elements can be leveraged to create a sophisticated install package. By relying on Microsoft standards, you'll be able to use features like Property elements to customize your application's entry in Add/Remove Programs, the Shortcut element to create Start menu shortcuts, and other specialized elements for building upgrade and patch support and more. This book will show you the fundamental ingredients needed to build a professional-grade installer using Windows Installer XML. The initial chapters will introduce you to the set of required elements necessary to build a simple installer. We'll then explore those basic elements in more detail and see how best to use them in the real world.In the ensuing chapters, you'll move on to learn about adding conditions that alter what the user can install, then how to add actions to the install sequence and how to author a user interface. We'll move on to advanced topics such as editing data in the Windows Registry, installing a Windows service, and building your project from the command line. Finally, you'll learn to localize your package for different languages and detect older versions during upgrades. Each chapter uses to-the-point examples to illustrate the best way to use the language.

Who is this book for?

If you are a developer and want to create installers for software targeting the Windows platform, then this book is for you. You'll be using a lot of XML so that you get accustomed to the basics of writing well-formed documents, using XML namespaces and the dos and don'ts of structuring elements and attributes. You should know your way around Visual Studio, at least enough to compile projects, add project references, and tweak project properties. No prior knowledge of Windows Installer or WiX is assumed.

What you will learn

  • Install, start, stop, and uninstall Windows Services at the time of setup
  • Make your project more modular with Fragments, ComponentRefs, and ComponentGroups
  • Learn tips for installing special types of files such as font files and how to optimize copying speed
  • Prevent users from installing your software on unsupported operating systems and introduce other pre-requisite checks
  • Gain an understanding of the order in which events happen during an install and how to add your own actions to this sequence
  • Build a customized user interface that meets the unique requirements of your project
  • Understand how WiX builds and links your files into the final MSI package and how to control this process
  • Read and write to the Windows Registry with XML
  • Build various language-specific installers without duplicating large amounts of code
  • Create rules for checking for and removing older versions of your software or to patch existing files

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 18, 2010
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781849513722
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Oct 18, 2010
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781849513722
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 158.97
WiX Cookbook
$48.99
WiX 3.6: A Developer's Guide to Windows Installer XML
$54.99
WiX: A Developer's Guide to Windows Installer XML
$54.99
Total $ 158.97 Stars icon
Banner background image

Table of Contents

13 Chapters
Getting Started Chevron down icon Chevron up icon
Creating Files and Directories Chevron down icon Chevron up icon
Putting Properties and AppSearch to Work Chevron down icon Chevron up icon
Improving Control with Launch Conditions and Installed States Chevron down icon Chevron up icon
Understanding the Installation Sequence Chevron down icon Chevron up icon
Adding a User Interface Chevron down icon Chevron up icon
Using UI Controls Chevron down icon Chevron up icon
Tapping into Control Events Chevron down icon Chevron up icon
Working from the Command Line Chevron down icon Chevron up icon
Accessing the Windows Registry Chevron down icon Chevron up icon
Controlling Windows Services Chevron down icon Chevron up icon
Localizing Your Installer Chevron down icon Chevron up icon
Upgrading and Patching Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(17 Ratings)
5 star 70.6%
4 star 17.6%
3 star 5.9%
2 star 5.9%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Harish.Viswanathan Aug 17, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Wonderful book covering an extensive range of topics on how to build your custom installer using Wix. Very helpful
Amazon Verified review Amazon
A. Davis Jan 27, 2011
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you want to learn WiX, but are not sure whether you need to spend money on this book instead of relying solely on free resources available online, do yourself a favor: buy the book. It will explain the basic concepts of both the Windows Installer technology and WiX development better than other tutorials, wikis, and help guides you may find (at least based on the resources I found by the time of writing this review). Not only does it describe what you need to do to accomplish certain tasks, but it also explains why you need to do this and that. It is definitely not a comprehensive guide, but for its size, it covers a lot of topics.I have some experience with MSI, InstallShield, and related installer technologies, but my knowledge of MSI internals is very limited (before switching to WiX, I mostly used Visual Studio Installer projects for building installers). I started learning WiX the hard way: reading user guide, tutorials, wiki; and in a couple of weeks I was able to write several installers for internal projects. Nevertheless, I still had very vague idea about the implementation (i.e. what does this property mean, why I need to include this attribute, what do these elements do), so I bought the book (well, my department did pay for it, but if not, I would've paid myself). The book cleared a lot of things for me.The book covers the fundamentals extremely well. What is a product, package, media? How do they relate? How do you use features, components, files? The book answers these and other questions in more detail than you would find elsewhere. I found the description of major upgrades (e.g. the matrix explaining the effects of scheduling removal of older version at different execution events) particularly helpful. Chapters covering user interfaces (using default wizards, modifying existing dialogs, customizing wizards) are very informational. So is the discussion of localization. Examples illustrate the topics nicely. The book offers sensible recommendations (e.g. avoid per-user setup packages).A couple of things I found somewhat confusing include description of properties, variables, etc, when it's not clear whether these get resolved during build time or deployment time and issues pertaining to 64-bit vs 32-bit installers (e.g. how system folders get resolved on various combinations of platforms and installers: 32-bit MSI/64-bit OS, etc). I wish the index were more comprehensive; most of the time when I needed to find something, I just flipped the pages.I agree with points made by other three reviewers, so I won't repeat them. In short, if you're planning to use WiX to write installers, get this book; you will find it quite helpful.
Amazon Verified review Amazon
Deep Roy Feb 07, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I got asked by my boss to make modifications to a WiX installer; after reading the first few chapters in this book, I was able to finish the WiX updates that I had to make.Since I couldn't very good documentation on the web, and because the author's writing style was informative, and easy to digest, and, because I finished my project, I gave the book 5 stars!
Amazon Verified review Amazon
seinerb Mar 28, 2011
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is very well written in an easy to read style. It has helpful coding examples and is a good reference for WiX coding.
Amazon Verified review Amazon
Petter Hesselberg Dec 01, 2010
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a well-written and thorough guide to WiX. You learn how to create an installer (simple or advanced), how to customize the UI, how to handle elevation (the dreaded UAC), how to handle upgrades and much more. Which is all very nice, but more or less what you'd expect from such a book.But there's more: A prerequisite for using WiX effectively is a fair understanding of how Windows Installer works (and that is not even remotely straight-forward). After reading this book I understand much more about the Windows Installer than I did before -- it is almost beginning to make sense.If only more software development books were like this one...
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.