Building with Wix.Targets

Heath Stewart

I’ve been away for a while working on a high priority issue that I’ll discuss in detail soon, as well as investigating a common issue regarding 32- and 64-bit installations about which I’ll write a new series of posts. For much of that work I’ve been using Windows Installer XML, or WIX, which allows me to build Windows Installer packages, merge modules, and patches (actually, just the .pcp files as input to PatchWiz.dll) using XML with support for preprocessor directives. You can find out more about WIX at http://wix.sourceforge.net/, as well as from Rob Mensching’s blog, who is the creator and “benevolent dictator” of WIX.

More recent distributions starting with build 2.0.3719.0 will include a file named wix.targets, which is a file you can include into an MSBuild project. MSBuild uses XML configuration files, similar to Ant and all its variants like NAnt, to build projects. You can import .Targets files (extension is meaningless, really) using the <Import> element and take advantage of the properties, tasks, and more that are imported. The wix.targets file defines several new tasks that correspond to candle.exe and light.exe, the compiler and linker in WIX, respectively.

At the top of the wix.targets file is a target named CheckRequiredProperties. That makes sure that you’ve specified both an OutputName and an OutputType property, as shown below:

<PropertyGroup>
    <OutputName>Example</OutputName>
    <OutputType>package</OutputType>
</PropertyGroup>

This will create a file names Example.msi. After defining those properties you must import the wix.targets file:

<Import Project=”wix.targets”/>

Then it’s just a matter of calling the targets defined in wix.targets, such as Build, which will set up, compile, and link. That didn’t work, though. The call to candle.exe was missing an input file. I couldn’t find any more required properties and I’m still trying to learn MSBuild, since after using NAnt for so long I wasn’t all too familiar with what was yet needed. I read the skimpy documentation and searched the Internet, but found nothing useful (one reason I’m posting this). So I talked to my colleague who has been working on MSBee.

Craig pointed out that the input @(Compile) was needed and that I could use an <ItemGroup> to define input source files. So, the final MSBuild project file that would compile Example.wxs and link the output as Example.msi would look like the following:

<Project DefaultTargets=”All” xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″>
    <PropertyGroup>
        <OutputName>Example</OutputName>
        <OutputType>package</OutputType>
    </PropertyGroup>
    <Import Project=”wix.targets”/>
    <ItemGroup>
        <Compile Include=”Example.wxs”/>
    </ItemGroup>
    <Target Name=”All” DependsOnTargets=”Build”/>
</Project>

0 comments

Discussion is closed.

Feedback usabilla icon