Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WIX HeatDirectory Task - Setting the preprocessorVariable

Tags:

msbuild

wix

I'm trying to set the preprocessor variable in wix and i'm unable to find an example of this or explanation on how to do it anywhere on the internet, i'm hoping somebody here can explain or show me where im going wrong!

I have tried the example shown here regarding setting var values http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/

The documentation for using the HeatDirectory taks in wix can be found here and is not very useful at all!

How do i set the preprocessorVariable to substitute the SourceDir for another variable name?

like image 405
Stuart Avatar asked Apr 09 '10 08:04

Stuart


People also ask

How do I use heat EXE on WiX?

Navigate to WiX's bin directory from a command prompt and type heat.exe -? to see information about its usage. To make things easy, consider adding the path to the WiX bin directory to your computer's PATH environment variable so that you won't have to reference the full path to the executable each time you use it.

How do you declare a preprocessor variable in WiX?

A wix variable can be referenced as $(var. foo) . Such a variable can be defined by passing -d command line arguments to candle.exe .


3 Answers

PreprocessorVariable for heat really need more doc and example... I've spend lots of time making it work too. This is how it works in my wixproj file:

<PropertyGroup>
  <DefineConstants Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">HarvestPath=..\distribution\Debug</DefineConstants>
  <DefineConstants Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">HarvestPath=..\distribution\Release</DefineConstants>
</PropertyGroup>

<Target Name="BeforeBuild">
  <HeatDirectory Directory="..\distribution\$(Configuration)"
               PreprocessorVariable="var.HarvestPath"
               OutputFile="HeatGeneratedFileList.wxs"
               ComponentGroupName="HeatGenerated"
               DirectoryRefId="INSTALLFOLDER"
               AutogenerateGuids="true"
               ToolPath="$(WixToolPath)"
               SuppressFragments="true"
               SuppressRegistry="true"
               SuppressRootDirectory="true"/>
</Target>

All you need is to define the variable. There is no magical "HeatDefinitions" :)

like image 86
laishiekai Avatar answered Oct 01 '22 18:10

laishiekai


I use Wix v3.10.

No need to explicitly call HeatDirectory MSBuild Task. ItemGroup with special name "HarvestDirectory" can be prepared, and later the "HarvestDirectory" target will process it. *.wsx file is created in the IntermediateOutputPath and is included in Compile list (processed by Candle).

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
...
  <MyFinalFolder Condition=" '$(MyFinalFolder)' == '' ">$(MSBuildProjectDirectory)\Final\</MyFinalFolder>
  <DefineConstants>FinalFolder=$(MyFinalFolder)</DefineConstants>
</PropertyGroup>

...

<Import Project="$(WixTargetsPath)" />
<Target Name="BeforeBuild">
  <!--
  No need to explicitly call HeatDirectory MSBuild Task.
  Instead follow documentation http://wixtoolset.org/documentation/manual/v3/msbuild/target_reference/harvestdirectory.html, which has sample and 
  important comment:
   This target is processed before compilation. Generated authoring is automatically added to the Compile item group to be compiled by the Candle task.
  So, *.wsx file created in the IntermediateOutputPath and included in Compile list (processed by Candle).

  The following ItemGroup with special name "HarvestDirectory" can be prepared, and later the "HarvestDirectory" target will process it, see
  C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\wix2010.targets
  -->
  <ItemGroup>
    <HarvestDirectory Include="$(MyFinalFolder)">
      <DirectoryRefId>INSTALLFOLDER</DirectoryRefId>
      <SuppressRootDirectory>true</SuppressRootDirectory>
      <SuppressCom>true</SuppressCom>
      <SuppressRegistry>true</SuppressRegistry>
      <ComponentGroupName>FilesComponentGroup</ComponentGroupName>
      <PreprocessorVariable>var.FinalFolder</PreprocessorVariable>
    </HarvestDirectory>
  </ItemGroup>
</Target>

The wxs file:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="INSTALLFOLDER">
            <Component Id="cmp9AA09F4A73FA53E2BDDE4B7BB5C91DFB" Guid="*">
                <File Id="fil9AA09F4A73FA53E2BDDE4B7BB5C91DFB" KeyPath="yes" Source="$(var.FinalFolder)\7z.dll" />
            </Component>
like image 23
Sergei Zinovyev Avatar answered Oct 01 '22 19:10

Sergei Zinovyev


I created an example project on GitHub showing how to successfully use the HarvestDirectory target, which is a higher-level thing that calls the HeatDirectory task. You don't need to directly call the HeatDirectory task yourself. You can see all of the example code here:

https://github.com/DavidEGrayson/wix-example-harvest-directory

Here are the most important parts:

foo.wixproj

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ProductVersion>1.0.0</ProductVersion>
    <DefineConstants>ProductVersion=$(ProductVersion);ItemDir=items</DefineConstants>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProjectGuid>27e80d9b-d8b6-423a-a6ff-1d9c5b23bb31</ProjectGuid>
    <SchemaVersion>2.0</SchemaVersion>
    <OutputName>foo-$(ProductVersion)</OutputName>
    <OutputType>Package</OutputType>
    <DefineSolutionProperties>false</DefineSolutionProperties>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <OutputPath>bin\$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>Debug;ProductVersion=$(ProductVersion)</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <OutputPath>bin\$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="foo.wxs" />
    <HarvestDirectory Include="items">
      <DirectoryRefId>ItemDir</DirectoryRefId>
      <ComponentGroupName>Items</ComponentGroupName>
      <PreprocessorVariable>var.ItemDir</PreprocessorVariable>
    </HarvestDirectory>
    <WixExtension Include="WixUIExtension" />
  </ItemGroup>
  <Import Project="$(WixTargetsPath)" />
</Project>

foo.wxs

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Name="Foo"
           Version="$(var.ProductVersion)"
           Manufacturer="Foo Inc."
           Language="1033"
           UpgradeCode="0c8504c9-4e62-4e2c-9e1c-4fbe1c478b37"
           Id="*">

    <Package Description="Foo"
             Manufacturer="Foo Inc."
             Compressed="yes"
             InstallerVersion="301" />

    <MajorUpgrade AllowDowngrades="no"
                  DowngradeErrorMessage="A newer version of this software is already installed."
                  AllowSameVersionUpgrades="no" />

    <Media Id="1" Cabinet="cabinet.cab" EmbedCab="yes" />

    <Property Id="ARPCOMMENTS">
      Foo package.
    </Property>
    <Property Id="ARPCONTACT">Foo Inc.</Property>
    <Property Id="ARPURLINFOABOUT">https://www.example.com/</Property>

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder" Name="PFiles">
        <Directory Id="INSTALLDIR" Name="Foo">
          <Component Id="readme">
            <File Id="readme" Name="README.txt" Source="README.txt" />
          </Component>
          <Directory Id="ItemDir" />
        </Directory>
      </Directory>
    </Directory>

    <Feature Id="Software"
             Title="Foo"
             AllowAdvertise="no"
             ConfigurableDirectory="INSTALLDIR">
      <ComponentRef Id="readme" />
      <ComponentGroupRef Id="Items" />
    </Feature>

    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
    <UIRef Id="WixUI_InstallDir" />
  </Product>
</Wix>
like image 21
David Grayson Avatar answered Oct 01 '22 18:10

David Grayson