How To Create a Wix Installer For a Console Application

Friday, 11 April 2014

This post will walkthrough the steps you can follow to easily create a Wix installer for a console application.

Before starting ensure you have the latest version of the Wix Toolset and the and the Visual Studio extension installed on your machine. Both of these can be downloaded from the Wix Toolset releases page. The examples shown in this post will be using VS2017.

Start Visual Studio then open up the solution that contains the console application you want to build the installer for. Once the solution has loaded, add a new project to it by right clicking the solution in the solution explorer then clicking add new project.

You should see a new section under the installed templates, called WiX Toolset with some new projects. Select Setup Project for WiX v4, then give the project a suitable name. When you are happy with the name, click ok.

The new project will have a file called Product.wxs. This is the main file needed for the installer. It specifies the name of the installer and is also where you reference any files that may be needed when the installer is being built.

If you haven't already, open up the Product.wxs file by double clicking it. In the product element insert a new GUID in the ID attribute & change the manufacturer to whatever you want. The value of the manufacturer attribute will be shown on the program in the add remove program screen. Add the attribute EmbedCab to the Media template element, and set its value to yes. You also need to remove the Fragment element that contains a ComponentGroup element, as we will be adding this in the next step.

Your product.wxs file should look like this:


The next thing we need to do is add the dependent files to the installer. We can do this by using a tool called heat, which is included as part of the Wix toolset, to harvest a directory. I wont go into detail about what heat does but put simply, it creates references to all the files needed by a project and stores these in a file.

To use heat, we'll add it to external tools. Open external tools from the tools menu. Then click add to add a new tool.

Give the fields the following values:

  • Title: Harvest Project
  • Command: C:\Program Files (x86)\WiX Toolset v3.8\bin\heat.exe (This should point to wherever you installed the wix toolset)
  • Arguments: dir $(BinDir) -dr INSTALLFOLDER -ke -srd -cg ProductComponents -var var.$(TargetName).TargetDir -gg -out ProductComponents.wxs (I wont explain these in this post but more info can be found here)
  • Initial directory: $(ProjectDir)
Check that the option Use Output Window is selected.

Click ok to save the tool.

Now that the tool has been added, we can harvest the project we wish to build the installer for. You can do this by selecting the project, then selecting Harvest Project, in the Tools menu on the main toolbar. You should see a message similar to this in the Output window:

 Windows Installer XML Toolset Toolset Harvester version 3.8.1128.0
 Copyright (c) Outercurve Foundation. All rights reserved.
Right click the project you just harvested, then select the option in the top bar of the solution explorer toshow all files. You should see a new file called ProductComponents.wxs.

This file contains references to all the components of the console application. By default the file is referenced in the Product.wxs file, so we do not need to reference it.
All we need to do now is add a reference to the console app project then move the ProductComponents file to the Wix project folder and include it in the project.

Now we need to add a UI to the installer. The WixUI library comes with built in dialog sets to provide a user interface for your installer.

To add a UI to the installer add a reference to the WiXUIExtension library, which can be found in the wix installation directory, to your project. Reference the UI in by adding these lines to the product.wxs inside the product element:


Once you have done this your installer is complete. All that's left to do is rebuild the wix project. When you have done this navigate to the bin directory of the wix project, then in the release or debug folder(depending on which configuration was selected when you rebuilt) you will find an MSI. Double click it to run and you should see the beginning of an install wizard.

In the next post i will show you how to customise the Installer UI.