Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Enabling Harvest (Heat.exe) in a Wix Setup Project

0.00/5 (No votes)
22 Aug 2017 1  
Enabling harvest within a Wix Setup project

Introduction

This article will explain how to enable and configure Harvest for a Wix Setup project. This works with Wix 3.10 and Visual Studio 2015.

Using the Code

Let's start by creating a new solution in Visual Studio.

Next, let's add a dummy ASP MVC site for testing purposes.

Now add a Wix Setup Project to your solution.

Your solution should look similar to:

Ok, now we have the initial projects setup. Let's go ahead and configure our HeatDirectory task. This requires us to modify the actual Wix setup project file that Visual Studio uses.

First, right click the setup project and select "unload".

Now right click again and select "edit".

Next, we need to find the following section (normally right at the bottom of the file and commented out):

<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>

Now, we want to configure our HarvestDirectory task. The following code should be inserted right under the above code:

<Target Name="BeforeBuild">
   <HeatDirectory 

      OutputFile="$(ProjectDir)\ProductInstallFiles.wxs" 

      Directory="..\Training.Wix.SampleSite" 

      ComponentGroupName="ProductFilesComponentGroup" 

      DirectoryRefId="INSTALLLOCATION" 

      AutogenerateGuids="true" 

      PreprocessorVariable="var.Training.Wix.SampleSite.ProjectDir" 

      SuppressRegistry="true" 

      SuppressRootDirectory="true" 

      ToolPath="$(WixToolPath)" 

      NoLogo="true" />
</Target>

So let's go through the code a little before we reload our project. The following values are required for the harvest to work.

OutputFileThis is the name of the file where harvest will save its references.
DirectoryThe directory to harvest.
DirectoryRefIdThe installation directory reference in Product.wxs.
ComponentGroupNameComponent group name used in Product.wix to install the files.
Preprocessor VariableThis must be in the format of (var.HarvestProjectNameSpace.ProjectDir).

The Preprocessor variable is used by Candle to determine where the source files live so they can be installed. It should be the namespace of your application that you are harvesting. Now we will reload our project and start setting up our product.wix.

I will briefly go over the package.wix file and setting it up initially. First, you would need to define the attributes on the product element. I have abstracted the values out into a separate configuration file. It should look simpler to the code below.

<product id="*" 

    language="1033" 

    manufacturer="$(var.ProductManufacturer)" 

    name="$(var.ProductName)" 

    upgradecode="$(var.ProductUpgradeCode)" 

    version="$(var.ProductVersion)">
</product>

The configuration file is imported at the top of the product.wix file and has the following settings:

<!--?xml version="1.0" encoding="UTF-8"?-->
<!--?include ProductConfiguration.wxi ?-->
<!--?define ProductName = "My Custom Product" ?-->
<!--?define ProductManufacturer = "Manufacturer" ?-->
<!--?define ProductVersion = "1.0.0.1" ?-->  
<!--?define ProductUpgradeCode = "INSERT_NEW_GUID" ?-->

Please make sure you update the Product upgrade code with a new guid. Now, we register out harvest component group with our feature element.

<feature id="ProductFeature" level="1" title="HarvestSetup">
   <componentgroupref id="ProductFilesComponentGroup">
</componentgroupref></feature>

And finally, tell wix where to install the files:

<fragment>
   <directory id="TARGETDIR" name="SourceDir">
      <directory id="ProgramFilesFolder">
   <directory id="INSTALLLOCATION" name="HarvestSetup">
   <directory id="ProductFilesComponentGroup"></directory>
   </directory>
   </directory>
   </directory>
</fragment>

Ok, so now we have the product set up, let's add a reference to the Wix Setup project to our test app. This is where the processing variable from the HarvestDirectory task. This allows us to access the ".ProjectDir" variable within our "ProductInstallFiles.wix".

Do a build of your application and you should see a reference in the output window to heat.exe. This is a good sign, if do not try dropping the references folder and enabling harvest.

If you can't see the "ProductInstallFiles.wix" file, then it may be excluded from the project. Simply show all files and include in the project.

The full project can be downloaded here.

History

  • 21/06/2016: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here