WIX HeatDirectory任务 - 设置预处理器变量

时间:2010-04-09 08:10:16

标签: msbuild wix

我正在尝试在wix中设置预处理器变量,我无法找到这样的示例或如何在互联网上的任何地方进行解释,我希望有人在这里可以解释或告诉我在哪里我出错了!

我已尝试过此处显示的有关设置var值的示例 http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/

在这里可以找到使用HotDirectory taks in wix的文档,它根本不是很有用!

如何设置preprocessorVariable以将SourceDir替换为另一个变量名?

6 个答案:

答案 0 :(得分:17)

PreprocessorVariable for heat真的需要更多的doc和例子......我花了很多时间让它工作。这是它在我的wixproj文件中的工作方式:

<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>

您只需要定义变量即可。没有神奇的“HeatDefinitions”:)

答案 1 :(得分:7)

我使用Wix v3.10。

无需显式调用HeatDirectory MSBuild Task。可以准备具有特殊名称“HarvestDirectory”的ItemGroup,稍后“HarvestDirectory”目标将处理它。 * .wsx文件在IntermediateOutputPath中创建,并包含在编译列表中(由Candle处理)。

win

wxs文件:

<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>

答案 2 :(得分:4)

您可以设置$(HeatDefinitions)属性以在父.wixproj文件中定义这些属性:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>  
        <HeatDefinitions>MySourcePath=..\src\Your.App\bin\Release</HeatDefinitions> 
    </PropertyGroup>

    <ItemGroup>
        <Compile Include="Phoenix.wxs" />
        <Compile Include="_HeatGeneratedFileList.wxs" />
    </ItemGroup>

    <Target Name="BeforeBuild">
        <HeatDirectory Directory="..\src\Your.App\bin\Release"
                       OutputFile="_HeatGeneratedFileList.wxs" 
                       PreprocessorVariable="var.MySourcePath" />
    </Target>
</Project>

我能找到的这个魔术属性(在整个互联网上)唯一提到的是wix-users邮件列表中的a single question about Team Build。我花了将近一天的时间试图修复未定义的预处理器变量错误,我偶然发现了运气。

答案 3 :(得分:4)

我在GitHub上创建了一个示例项目,展示了如何成功使用HarvestDirectory target,这是一个调用HeatDirectory任务的更高级别的东西。您不需要自己直接调用HeatDirectory任务。您可以在此处查看所有示例代码:

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

以下是最重要的部分:

<强> 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>

答案 4 :(得分:3)

我发现它是什么,在尝试各种事情1天后,上面的链接是正确的但是要在热目录任务中使用var,你必须这样做。

<HarvestDirectory Include="$(ProjectDirectory)\" >
      <DirectoryRefId>WEBDIR</DirectoryRefId>
      <KeepEmptyDirectories>true</KeepEmptyDirectories>
      <SuppressRegistry>true</SuppressRegistry>
      <ComponentGroupName>DynamicWebFiles</ComponentGroupName>
      <PreprocessorVariable>var.WixDynamicSourceDirectory</PreprocessorVariable>
   </HarvestDirectory>

答案 5 :(得分:0)

我有一个非常大的安装工具包,可以在Visual Studio 2013中构建(包括一些与主项目相关的工具,一个Windows服务和一个具有非平凡目录结构的Web应用程序)。我还在学习如何使用WiX,我仍在制作,测试和改进WiX项目。目前,我使用

形式的命令将收获任务设置为构建事件

“C:\ Program Files(x86)\ WiX Toolset v3.9 \ bin \ heat.exe”dir“$(SolutionDir)\ MyProjectDir \ bin \ $(ConfigurationName)” - cg MyComponentRef -ag -dr MYINSTALLDIR - srd -wixvar -var var.MySourceFiles -sreg -out“$(SolutionDir)\ Deployment \ My Installer Project \ ComponentList.wxs”-t“$(SolutionDir)\ Deployment \ My Installer Project \ FileFilter.xslt”

此命令只捕获项目的bin \ Debug(或bin \ Release)文件夹中的所有文件,然后使用xml样式表转换过滤它。有很多收获像这样收集,因此维护所有源文件变量(命令中的“var.MySourceFiles”参数)变得乏味且容易出错。最初,我已经将声明添加到项目的预处理器变量中,但我想要一些更“自足”的东​​西。使用我在WiX tricks and tips找到的有用提示,我声明了一个包含内容的新包含文件“PreprocessorVars.wxi”

  

并获取xslt以将其包含在heat.exe生成的输出中,并带有代码段

    <xsl:processing-instruction name="include">
        $(sys.CURRENTDIR)\PreprocessorVars.wxi
    </xsl:processing-instruction>

xslt现在生成如下所示的输出:

<?xml version="1.0" encoding="utf-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
        <?include 
                $(sys.CURRENTDIR)\PreprocessorVars.wxi
            ?>
        <Fragment>
            <DirectoryRef Id="MYINSTALLDIR" />
        </Fragment>
        <Fragment>
            <ComponentGroup Id="MyComponentRef">
                <Component Id="xyz" Directory="MYINSTALLDIR" Guid="*">
                    <File Id="abc" KeyPath="yes" Source="$(var.MySourceFiles)\MyProjectExecutable.exe" />
                </Component>
            </ComponentGroup>
        </Fragment>
    </Wix>

哪个Wix处理没有任何错误。