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.
OutputFile | This is the name of the file where harvest will save its references. |
Directory | The directory to harvest. |
DirectoryRefId | The installation directory reference in Product.wxs. |
ComponentGroupName | Component group name used in Product.wix to install the files. |
Preprocessor Variable | This 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:
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