Application Development

Wix Installer Tutorial for Visual Studio

Welcome to this DMC video blog titled Wix Installer Tutorial for Visual Studio. My name is Spencer Glesmann, and I am a system's engineer at DMC. Today I'm going to go over the basic of Wix to get your started in creating custom installers for .Net applications. To get started we first need to download and install the latest version of Wix from, which right now is at version 3.7. Once downloaded, run the Wix installer. A reboot may be be necessary. Once installed, launch Visual Studio, preferably with your project or solution open.

I have created a very simple 'Hello World' application, called Wix Example Application. The executable has a config file and exe documentation file. There's also a class library called Wix Library. I have made the executable dependent on both the class library and the config file. Now we can get started on adding our installer. So in order to get started with setting up our installer, we first want to go the solution explorer. Right click on the solution, click add new project. Hopefully you'll see a familiar window, the new project window. We're going to select from the left-hand menu Windows Installer.xml. Select set-up project and we're going to call this Installer. Now we're going to add some references. Specifically, I want to add all the projects in my solution that I want to include in my installer.

A way to do that is you right click, select add reference, go to projects, which is here, select all projects you want to include in the installer, add, okay, so now they're referenced, and then we can start messing with our xml. So the first thing we'll see is the product ID is set to an asterisk. This means it's using [dynamic mode], which is fine. The name, we'll call this Wix Installer. The language we default to your region. Version is going to default to 1.0. Manufacturer we'll set to DMC. Upgrade Code, this is a good which is used for upgrading. If we're installing Version 2 it's used to determine if Version 1 is installed or if Version 2 is the first installation of this application. Don't change this, if you ever want to upgrade, you'll need this exact good in order for it to upgrade, correctly at least.

And we have a package, we want to set the ID to be dynamic as well, by setting it to an asterisk. Installer version, compressed, we can leave alone. Install Scope” I'm going to leave it as per machine, but you can switch this to per-user, depending the requirements of your application. Major Upgrade: we're not going to mess with, but this default is preventing us from downgrading. This project name is a magic string which gets replaced with the name of your product, so Wix Installer. Media Template we're going to embed cab to “yes.” This is going to embed the cabinet file into the MSI so you only have one file to deliver to end users rather than two, two being your MSI and your cabinet file.

Then we want to set the Feature ID. We've got a product feature. Title is Installer Level 1. This is used down the road for determining if we want to install everything or only install application in central features versus documentation files. We'll leave this alone, but it's a pretty powerful tag as well. Within our feature, we only have one thing, it's a component group reference. So component group ref. We're referencing the product components component group, which is down at line 23. We'll get there in a sec. So then we have a fragment with a directory structure. This is going to be the output directory structure, so it's going to actually install it in C which is this target DIR. Program Files, or Program Filesx86, depending on whether you're running a 32 bit or a 64 bit machine, and then it's going to put it in an install folder.

So this will change to Wix Example Application. Okay, so if we go back down to our component group, we'll see that the directory for that component group is install folder. Another note is that ID is how we reference anything in Wix somewhere else, so everything for the most part is going to need an ID, with exception I believe, of components within a component group, because the components are in a group so we're always going to reference them together as a theory at least so we can get around that.

For every component we need to have a [GUI], which is kind of a pain, but there's a handy tool in Visual Studio called Create [GUI], I believe I already have that open, which looks like this. If you select option four and then you [GUI] a copy, you can just copy and paste it right in there. So we'll first add a- our executable. So let's do Source equals- we're going to use a variable which is var.wixexampleapplication.targetpath, so that is referencing our output directory so it's going be Bin Debug Wicksexampleapplication.exe. Set the key path actually to yes. If we don't do this, then we need to add an ID for the component. If we do this then we don't need to have it as a component. So let's do the same thing for our DOL.

Sourcebar.wixlibrary.targetpath, and then finally we're going to add a component for our config file. So it starts out the same way, but we're going to- this time we're going to use a relative path instead of a variable because we don't have a variable for the config file. So a way to do this is ...wixexampleapplication bin debug wixexampleapplication, and then set the key path again to be yes, and then we're done! So congratulations, you've successfully created your first installer using Wix. For proof, we can go to installer, bin, debug, we have our installer. It's going to install these three files in this folder structure. Thank you for listening and I hope you've learned something!