Wix Target for MSBuild

Wix is great, but having to use the commandline tools is not so cool to do. So, to save time and effort I made a MSBuild target to do the heavy lifting. Be aware that I haven't fully tested all possible scenario's, so there might be some room for improvement.

Installation

To install the build target, just copy the contents of the Wix folder in the zipfile over to your "%programfiles%MSBuildWix" directory.

Configuration

The build target needs some configuration, the properties described below can be configured using a <PropertyGroup> element inside your buildscript.

  • WixToolsPath – The path to the location where WiX 2.0 is installed (Default is: C:Program filesWindows Installer XML)
  • OutputDirectory – The path where to put the created msi file
  • InstallerName – The name of the installer, without extension
  • SourceBasePath – The path where the sourcefiles are located

Usage

To use the Wix build target you need to include the targets file using the following statement:

<Import Project="$(MSBuildExtensionsPath)WixWix.targets"/>

You also need to provide the target with a set of scripts to compile and optionally the necessary libraries and localization files to complete the installer. All of these files are divided up into three itemgroups.

  • WixLibrary
  • LocalizationFile
  • WixScript

The custom target can be called from targets defined in your buildscript. A sample on how to use the Wix target shown below:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CreateSetup">
  <!-- Include the custom build targets -->
  <Import Project="$(MSBuildExtensionsPath)WixWix.targets"/>

  <!-- Item group for the localization files -->
  <ItemGroup>
    <LocalizationFile Include=".langWixUI_en-us.wxl"></LocalizationFile>
    <LocalizationFile Include=".langen-us.wxl"></LocalizationFile>
  </ItemGroup>

  <!-- Item group for the libraries needed by the installer -->
  <ItemGroup>
    <WixLibrary Include="$(WixToolsPath)binwixui.wixlib"></WixLibrary>
  </ItemGroup>

  <!-- Item group for the Wix scripts -->
  <ItemGroup>
    <WixScript Include="Product.wxs"></WixScript>
  </ItemGroup>

  <!-- Target to build the actual installer -->
  <Target Name="CreateSetup">
    <!-- Snip -->
    <CallTarget Targets="BuildWixInstaller"/>
  </Target>  
</Project>

Drop me a line if you have improvements. 🙂