John Dyer
John Dyer

Reputation: 2358

Deploy Any CPU build with WiX to x86 using MSBuild

I have a set of solutions that build a complete .NET Any CPU application. I have a WiX project that will deploy that application as x86 and I can run this all manually in Visual Studio 2013 without any issues. Now I'm trying to get this to work in MSBuild / TFS. The conflict is that I need to specify Any CPU for the code and x86 for WiX. My initial thought was to just hack the WiX solution / project to be Any CPU in name but let it actually make an x86 MSI. However the wixproj setup won't allow Any CPU to be used. I would expect the same issues with Any CPU and a 64 bit installer. WiX seems determined to not allow Any CPU.

The remaining option that I'm seeing here is to not build the WiX part with MSBuild but instead handle that in a post build batch file. However it really seems you should be able to deploy Any CPU code with WiX.

Upvotes: 0

Views: 1903

Answers (3)

bradfordrg
bradfordrg

Reputation: 1903

You could create a custom xaml build template with an extra MSBuild step to build your setup project after the main build. I used this technique with three distinct MSBuild build steps:

Custom build template

In the additional MSBuild steps, you could hard code the solution names, which might be appropriate if you only build one product. If you want more flexibility you can re-arrange the build process arguments and feed these into the MSBuild steps. The team build process editor will automatically pick up the new process argument layout:

Build process settings

See https://msdn.microsoft.com/en-us/library/dd647551.aspx for a general guide to customizing build templates. The build templates in TFS Build 2013 are much easier to follow and modify compared to earlier versions.

Upvotes: 0

Petrik
Petrik

Reputation: 1981

It seems that WiX projects use the platform configuration to determine what mode they're building in so they only allow x86 or x64 platform configurations. So it is not possible to build a WiX project in the 'Any CPU' platform configuration because that platform does not exist.

The easiest option for to get your WiX project build in 32-bit (or 64-bit) is to set up a solution that has both your .NET projects and your WiX projects, like the image below. The projects in the first rectangle are the C# projects and the second rectangle has the WiX project in it.

Visual Studio solution with C# and Wix projects

Then setup one or more solution configurations for this solution with the .NET projects as 'Any CPU' and the WiX project as x86 (or x64 for the 64-bit installer). For example like this:

Solution configuration at Any CPU

If you want to have both an 32-bit and a 64-bit installer then I would recommend making an x86 solution configuration and a x64 solution configuration. Set your .NET projects to build either in the 'Any CPU' configuration or in the respective bitness (x86 or x64) and set the WiX project to build in the correct bitness (x86 for the 32-bit installer and x64 for the 64-bit installer).

Note that in either case you need to make sure that the installer project picks the binaries from the location where they are being placed by the compiler.

Then set your TFS build definition to build this solution with the solution configuration that you created. Like in the image below

enter image description here

TFS will then build your solution with the correct solution configuration which should build both your .NET projects and your WiX project in their respective correct configurations.

Upvotes: 2

Christopher Painter
Christopher Painter

Reputation: 55591

Just tell it to build Any CPU and x86 platforms and it'll build or skip the projects as needed. It should work just fine. You'll see messages in the build logs that say something like platform invalid skipping and if you don't want that just create the missing platform in each solution and configure the projects to not build for it.

Upvotes: 0

Related Questions