andyopayne
andyopayne

Reputation: 1368

WIX Heat PreBuild Variable Name for Directory to Harvest

I'm working on a new installer (first one using WiX). I'm using Heat to harvest the output files from a referenced project solution and I've got it working well. The issue is that I'm using an absolute path to my harvest directory in my heat call and I'd like to replace that with a variable (preferably in a configuration.wxi file) so that others that I'm working with can quickly change the paths on their machines. Here's my heat pre-build event call:

call “$(WIX)bin\heat.exe” dir "C:\MyProjectPath\bin\Release" -dr APPLICATIONROOTDIRECTORY -cg ApplicationComponents -gg -g1 -scom -sreg -sfrag -srd -suid -var var.sourcePath -out “$(ProjectDir)Fragments\MainAppFiles.wxs”  -t $(ProjectDir)Transform.xslt

This statement works, but as you can see I have an absolute path located after the dir tag that I'd like to replace with a variable name. I've read the documentation page for heat tags and I've tried many other ways to do this (including defining preprocesser variables) but nothing seems to work. Can anyone point me in the right direction?

Upvotes: 3

Views: 4291

Answers (1)

Arkady Sitnitsky
Arkady Sitnitsky

Reputation: 1886

There are 2 ways to call heat process, in the before build target or in prebuild event.

The Prebuild event calls directly the heat process in order to generate automatically MyComponents.wxs file as you written above.

And the before build target doing the same when using "HeatDirectory" or "HarvestDirectory".

The main difference is which of this option is more suitable for you. Command line,as you described above, or xml style like:

<Target Name="BeforeBuild">
 <HarvestDirectory Include="$(SourceDir)">
    <DirectoryRefId>INSTALLDIR</DirectoryRefId>
    <ComponentGroupName>cmpMain</ComponentGroupName>
    <PreprocessorVariable>var.SourceDir</PreprocessorVariable>
    <SuppressUniqueIds>false</SuppressUniqueIds>
    <SuppressCom>true</SuppressCom>
    <SuppressRegistry>true</SuppressRegistry>
    <SuppressRootDirectory>true</SuppressRootDirectory>
    <KeepEmptyDirectories>false</KeepEmptyDirectories>
    <Transforms>DefaultTransform.xsl</Transforms>
 </HarvestDirectory>
</Target>

To use the $(SourceDir) you can define property group as:

  <SourceDir Condition="Exists('$(TF_BUILD_BINARIESDIRECTORY)')">$(TF_BUILD_BINARIESDIRECTORY)\testfolder</SourceDir>
  <SourceDir Condition="!Exists('$(TF_BUILD_BINARIESDIRECTORY)')">$(MSBuildProjectDirectory)..\..\..\testfolder</SourceDir>

I have putted example for local build and TFS build.

Upvotes: 3

Related Questions