Learn from my mistakes, you don't have time to make them yourself

Deploying websites with WiX

I posted back in 2010 about how to get WiX to correctly deploy a website using harvesting. It was a rather clunky solution that required changes to your development machine (and the same for everyone in your team) as well as any build infrastructure you are running. I have now discovered a much cleaner solution using harvest transforms (tested using WiX 3.7).

As a recap, harvesting pulls files from the project reference compilation into the MSI and puts them into a single output directory. This means that website content and the binaries will be in the root folder of the deployment. This is no good for websites that require binaries to be placed into a bin folder.

Here is how to fix it. Firstly, you need to add your web project as a project reference in your WiX project.

You then need to enable harvesting on the properties of that project reference. Set the Directory Id to the Id in your file system that WiX will use for the website. The Project Output Groups is fine with the default of BinariesContentSatellites.

I do not recall this being an issue in previous versions, but this won’t actually harvest the project. It seems like harvesting is now disabled by default. This needs to be enabled by editing the WiX proj file and adding the following into the first PropertyGroup element.

<EnableProjectHarvesting>true</EnableProjectHarvesting>

Next, you need to make sure that the Product.Generated component group reference is emitted by your MSI. For example:

Compile the WiX project and deploy the MSI. You should now have a website deployed with the binaries in the bin directory.

The only disadvantage with this way of deploying websites is that a website publish has not been executed. This means that operations like xml transformations have not been actioned. We handle those scenarios in WiX anyway (see the util:XmlConfig above) so this isn’t a concern. We simply remove web.Debug.config and web.Release.config from the solution so they don’t end up getting bundled in the MSI in the first place.