Click here to Skip to main content
Click here to Skip to main content
Go to top

Building Installation Packages with Windows Installer XML

, 24 Feb 2012
Rate this:
Please Sign up or sign in to vote.
How to install packages with Windows Installer XML.

A while ago, I needed to package and deploy an application and I did not want to use Visual Studio Setup and Deployment, I opened my firefox and decided to look for an alternative, what I got is WIX, windows installer xml.

So, I did some background check about WIX and I found out that its the right tool for what I needed to do, because it gives me full control as a developer to determine how my application is going to be installed on the clients' machines and gives full unrestricted access to Windows Installer functionality, but the learning curve associated with it is much and knowledge of xml is a prerequisite.

WIX is a free open source toolset that is used to build Windows installation packages from XML source code, originally it was developed by Microsoft but its now being maintained by Rob Mensching. It is written in C# and WIX itself is much like a programming language, but nothing to worry about, because with the knowledge of xml, the problem is half solved.

Now, don't let me bore you and lets get started, in this post, I am going to use WIX to deploy a c# contact manager application that saves and retrieves data from an SQLite database. First of all you need to download the WIX toolset which contains visual studio plugin that install WIX project templates into visual studio, download the binaries here. After installing the toolset, it will install templates like this into visual studio.

wix  templates

The Setup project templates is what you need to add to the solution that contains the project you want to package, adding the wix setup project to contact manager gives:

wix  templates

Note that a Product.wxs file has been added to the Setup project, this is an xml file that contains the setup code for the project. Another important point to note that is that you will be using guids heavily when using wix, good news is that visual studio has a guid generating tool, which can be accessed by clicking on the Tools menu and then select Create Guid.

The next thing to do is to right click the setup project and add reference to the project to be packaged, this will give us access to some project variables that can be referenced in the WiX source code, in this case I add reference to the ContactManager C# application. You also need to add reference to WixUIExtension.dll and WixUtilExtension.dll both contained in the WIX installation folder, these two libraries will expose some cool features that can be used to build a professional installation package.

Apart from the project variables that you have access to after adding reference to the project to be packaged, there are other variables that are exposed by WIX which can be used to build a robust installation package.

Inside the Product.wxs file is the <Product> element which includes <Package>, <Media>, <Directory>, <Component> and <Feature> elements needed to build an MSI package.

The <Product> element has some useful attributes such as Name="this is the name of the project" Manufacturer="this is the product manufacturer" Version, Language and so on.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns=""
<Product Id="287a3ea0-9a41-4b72-9c1d-abd16a2c3621" 
  Name="Contact Manager" Language="1033" Version=""
  Manufacturer="Ayobami Adewole"

There is a <Package> element, with the attribute Compressed="yes" indicating that the package to be generated should be compressed. The <Media> element has attribute EmbedCab="yes" which indicates that the cabinet should be embedded.

<Package InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="" EmbedCab="yes" />

The <Directory> element is used in various directory manipulations, such as accessing system's directory, creating new directory during installation and so on. The variable var.PlatformProgramFilesFolder gets a reference to the client's system Program files folder. In the snippet below, the <Directory> element with attribute Id="ApplicationProgramsFolder" is used to get reference to the client's system Application Programs Folder. <Shortcut> element is used to add shortcut, it has attribute Target="[INSTALLLOCATION]ContactManager.exe" which specifies the target of the shortcut, where INSTALLOCATION gets reference to the directory where the application is installed on the system. The <RegistryValue> element is used to add entries to the system's registry.

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="$(var.PlatformProgramFilesFolder)">
<Directory Id="INSTALLLOCATION" Name="Contact Manager">
 <Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" 

     Name="Contact Manager"/>

<DirectoryRef Id="ApplicationProgramsFolder">
 <Component Id="ApplicationShortcut" 
 <Shortcut Id="ApplicationStartMenuShortcut"
     Name="Contact Manager"
     Description="Contact Manager"
        <Shortcut Id="UninstallProduct"
      Name="Uninstall Contact Manager
      Arguments="/x [ProductCode]"
      Description="Uninstalls Contact Manager" />
      <RemoveFolder Id="ApplicationProgramsFolder" 
       <RegistryValue Root="HKCU" 
      Key="Software\Ayobami Adewole\Contact Manager" 

     Name="installed" Type="integer" Value="1" KeyPath="yes"/>

The <Feature> element is used to add all the features to the installation package, this is where all the files, directories are added to the package using various elements such as <Component>, <ComponentRef>, <ComponentGroupRef>, <File>, and so on. The Installation user interface that the user installing the application sees is also constructed here, the default user interface can be used or better still your custom defined bitmap images can be added to the project and explicitly specified using the elements <WixVariable Id="WixUIBannerBmp" Value="Banner.bmp" /> for the banner that will appear on all dialog boxes during installation and <WixVariable Id="WixUIDialogBmp" Value="Dialog.bmp" /> for the first and last dialog boxes, where Banner.bmp and Dialog.bmp must have been added to the Wix project.

<Feature Id="ProductFeature" Title="Contact Manager" Level="1">
      <ComponentRef Id="ApplicationShortcut" />
      <ComponentGroupRef Id="Product.Generated" />
      <ComponentGroupRef Id="Components" />
    <UIRef Id="WixUI_InstallDir" />
       Value="Launch Contact Manager" />
    <Property Id="WixShellExecTarget"
      Value="[INSTALLLOCATION]ContactManager.exe" />
    <CustomAction Id="LaunchApplication" BinaryKey="WixCA" 
        DllEntry="WixShellExec" Impersonate="yes" />
   <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" 
                 WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
    <WixVariable Id="WixUIBannerBmp" Value="Banner.bmp" />
    <WixVariable Id="WixUIDialogBmp" Value="Dialog.bmp" />

Adding files to the package can be achieved by nesting a <File> element inside the <Component> element and setting the Source attribute. The variable var.ContactManager.TargetDir gets reference to the base directory of the project to be packaged.

<Component Id="cmp3CD83BDDE0C679AC83F36ABCCC44B85F" Guid="*">
    <File Id="fil48A9C4979800A1A57A6A9059191EC957" 



After the necessary files and components have been added, the Wix setup project is then built, checking the Debug folder of wix setup project, you can now find Setup.msi file which is the installation package. Double clicking to install gives:

installation ui

WhWhen you click next another dialog box comes up:

installation ui

This is the last screen after the installation is completed.

installation ui

The full source code can be downloaded here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ayobami Adewole
Software Developer Teqbridge Limited
Nigeria Nigeria
A Microsoft Certified Solutions Developer (MCSD), Most Valuable Blogger (MVB). Passionate about Sofware Development and VoIP
Follow on   Twitter

Comments and Discussions

GeneralMy vote of 3 Pinmemberankit_the_champ31-Mar-14 11:49 
QuestionDoes it work with Asp.Net MVC4 PinmemberAjinkyaaher11-Oct-13 3:34 
Questionneed help in creating a set up Pinmembersanty143all11-Nov-12 20:02 
AnswerRe: need help in creating a set up PinmemberAyobami Adewole13-Nov-12 0:16 
QuestionNice article! PinmemberMember 356638031-Jul-12 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 24 Feb 2012
Article Copyright 2012 by Ayobami Adewole
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid