Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WiX Cookbook

You're reading from   WiX Cookbook Over 60 hands-on recipes packed with tips and tricks to boost your Windows installations

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781784393212
Length 260 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nicholas Matthew Ramirez Nicholas Matthew Ramirez
Author Profile Icon Nicholas Matthew Ramirez
Nicholas Matthew Ramirez
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Organizing and Building WiX Projects FREE CHAPTER 2. Installing Files and Directories 3. File and Folder Permissions 4. Shortcuts 5. Editing XML Files during Installation 6. Custom Actions 7. Installing Wizards 8. Users and Groups 9. Handling Prerequisites 10. Installing Websites 11. Linking to the Web 12. Installing SQL Server Databases 13. Admin Tasks Index

Compiling a WiX installer on a build machine using MSBuild

The WiX Toolset places its compiler and linker in C:\Program Files (x86)\WiX Toolset v3.9\bin. This is fine when compiling on your own machine but becomes a concern when you'd like to share your project with others or have it compile on a build server. WiX will have to be installed on each computer that builds the project.

Alternatively, we can store the WiX tools in source control, and then whoever needs to build a setup project can get everything they need by cloning the repository. This will also help us keep a handle on which version of WiX we're compiling against on a project-by-project basis.

In this recipe, we'll store the WiX binaries in a fictitious source control directory on the C: drive. We'll then update the .wixproj file of a setup project to use the MSBuild tasks stored there. I will be using a server with the Windows Server 2012 R2 operating system installed on it. You should be able to follow along with other versions of Windows Server.

Getting ready

To prepare for this recipe, perform the following steps:

  1. Install the .NET Framework 3.5. It's needed by the WiX build tasks. In Windows Server 2012 R2, it can be installed as a feature within Server Manager:
    Getting ready
  2. Next, we'll need the MSBuild engine, which is part of Microsoft Build Tools. It can be downloaded from http://www.microsoft.com/en-us/download/details.aspx?id=40760.
  3. After installing MSBuild, add its installation directory to the computer's PATH environment variable. Get there by right-clicking on This PC in file explorer and then going to Properties | Advanced system settings | Environment Variables.... Scroll through the list of system variables until you find the one labeled Path. Highlight it, click on Edit..., and then add the path to the MSBuild directory into the Variable value field, preceded by a semicolon. Then, click on OK:
    Getting ready

How to do it…

Download the WiX binaries and update your setup project to use the included MSBuild tasks:

  1. Open a browser, navigate to http://www.wixtoolset.org, and follow the link to the downloads page. Download wix39-binaries.zip:
    How to do it…
  2. Make sure that the ZIP file is unblocked by right-clicking on it, choosing Properties, clicking on Unblock (if you don't see it, just continue to the next step), and then on OK.
  3. Extract the contents of the ZIP file to C:\SourceControl\WiX39. Perform this step on both the server and on your own development computer so that our WiX projects can be built in both places using the MSBuild tasks from this folder (note that in a real-world scenario, our source control system would be responsible for copying the binaries to each computer):
    How to do it…
  4. We will build a simple setup project to confirm that we've got everything on the server configured correctly. Create a setup project on your development machine and call it BuildMachineInstaller.
  5. Open the BuildMachineInstaller.wixproj file and add the WixToolPath, WixTargetsPath, and WixTasksPath properties as shown, making sure that the value of WixToolPath ends in a backslash:
    <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
        <ProductVersion>3.9</ProductVersion>
        <ProjectGuid>f80ca9fc-8e42-406e-92f9-06e484e94d67</ProjectGuid>
        <SchemaVersion>2.0</SchemaVersion>
        <OutputName>BuildMachineInstaller</OutputName>
        <OutputType>Package</OutputType>
        <WixToolPath>C:\SourceControl\WiX39\</WixToolPath>
        <WixTargetsPath>$(WixToolPath)wix.targets</WixTargetsPath>
        <WixTasksPath>$(WixToolPath)WixTasks.dll</WixTasksPath>
        <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
        <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    </PropertyGroup>
  6. Copy the BuildMachineInstaller solution folder and all of its subfolders to C:\SourceControl on the build server.
  7. Open a command prompt via Run | cmd, execute the following commands to change the directory to the BuildMachineInstaller folder and compile the solution using MSBuild:
    cd C:\SourceControl\BuildMachineInstaller
    
    msbuild BuildMachineInstaller.sln 
    

How it works…

We started with a blank slate of a freshly installed Windows Server 2012 R2 operating system. Therefore, we had to install all the required software including .NET Framework 3.5 and Microsoft Build Tools 2013. The latter gives us the MSBuild engine, whose path we included in the computer's PATH environment variable.

Next, we downloaded the WiX binaries and copied them to C:\SourceControl. With a source control system, these files could be shared among all computers that need to compile our setup projects. We also had to update our project's .wixproj file so that it knew where to find these WiX binaries. This is accomplished by adding three MSBuild properties: WixToolPath, WixTargetsPath, and WixTasksPath. The first property sets the path to the WiX binaries, the second to the wix.targets file, and the third to WixTasks.dll. With all of this setup out of the way, we opened a command prompt, navigated to the folder where our solution file was on the build server, and compiled it using MSBuild.

You have been reading a chapter from
WiX Cookbook
Published in: Jan 2015
Publisher:
ISBN-13: 9781784393212
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image