msbuild+wix:如何让heatdirectory使用defineconstants的变量?

3
大家好:这是我的第一篇帖子!
我正在尝试使用VisualStudio的“定义常量”功能获取Wixproj,以便使用HeatDirectory获取其源目录。我定义了一个名为SourceBinaries的常量,值为c:\ someproject \ bin \ release。
目的是为多个项目使用相同的wixproj /安装程序,并使用TFS-Build自动化整个过程...
然而,目录标记从未获得SourceBinaries的值。
以下是XML代码:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
blah..
    <OutputName>ProjectSetup</OutputName>
blah..
  </PropertyGroup>
  <PropertyGroup>
    <OutputPath>bin\$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>SourceBinaries=c:\someproject\bin\release\</DefineConstants>
  </PropertyGroup>
  <ItemGroup>
blah..
  </ItemGroup>
   <Import Project="$(WixTargetsPath)" />
  <Target Name="BeforeBuild">
    <HeatDirectory NoLogo="$(HarvestDirectoryNoLogo)" 
        Directory="$(SourceBinaries)" 
        PreprocessorVariable="var.SourceBinaries" 
        SuppressAllWarnings="$(HarvestDirectorySuppressAllWarnings)" 
        SuppressSpecificWarnings="$(HarvestDirectorySuppressSpecificWarnings)" 
        ToolPath="$(WixToolPath)" 
        TreatWarningsAsErrors="$(HarvestDirectoryTreatWarningsAsErrors)" 
        TreatSpecificWarningsAsErrors="$(HarvestDirectoryTreatSpecificWarningsAsErrors)" 
        VerboseOutput="$(HarvestDirectoryVerboseOutput)" 
        AutogenerateGuids="$(HarvestDirectoryAutogenerateGuids)" 
        GenerateGuidsNow="$(HarvestDirectoryGenerateGuidsNow)" 
        OutputFile="ProductFiles.wxs" 
        SuppressFragments="$(HarvestDirectorySuppressFragments)" 
        SuppressUniqueIds="$(HarvestDirectorySuppressUniqueIds)" 
        Transforms="Transforms.xsl" 
        ComponentGroupName="ProductFiles" 
        DirectoryRefId="INSTALLLOCATION" 
        KeepEmptyDirectories="false" 
        SuppressCom="%(HarvestDirectory.SuppressCom)" 
        SuppressRootDirectory="true" 
        SuppressRegistry="%(HarvestDirectory.SuppressRegistry)">
    </HeatDirectory>
 blah..
 </Target>
  <Target Name="AfterBuild">
blah..
  </Target>
</Project>

无论我尝试什么,都导致了“错误:未为所需参数”Directory"提供值的"HeatDirectory"任务。
有人能帮我解决这个问题吗? 提前致谢...
Didier
2个回答

3

我认为您主要的困惑在于在<DefineConstants>元素中定义的变量仅适用于.wxs文件,但它们不会在.wixproj文件本身中生效。

要解决这个问题,您可以尝试以下方法:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
blah..
    <OutputName>ProjectSetup</OutputName>
blah..
  </PropertyGroup>
  <PropertyGroup>
    <OutputPath>bin\$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
    <SourceBinaries>c:\someproject\bin\release</SourceBinaries>
    <DefineConstants>SourceBinaries=$(SourceBinaries)</DefineConstants>
  </PropertyGroup>
  <ItemGroup>
blah..
  </ItemGroup>
   <Import Project="$(WixTargetsPath)" />
  <Target Name="BeforeBuild">
    <HeatDirectory NoLogo="$(HarvestDirectoryNoLogo)" 
        Directory="$(SourceBinaries)" 
        PreprocessorVariable="var.SourceBinaries" 
        SuppressAllWarnings="$(HarvestDirectorySuppressAllWarnings)" 
        SuppressSpecificWarnings="$(HarvestDirectorySuppressSpecificWarnings)" 
        ToolPath="$(WixToolPath)" 
        TreatWarningsAsErrors="$(HarvestDirectoryTreatWarningsAsErrors)" 
        TreatSpecificWarningsAsErrors="$(HarvestDirectoryTreatSpecificWarningsAsErrors)" 
        VerboseOutput="$(HarvestDirectoryVerboseOutput)" 
        AutogenerateGuids="$(HarvestDirectoryAutogenerateGuids)" 
        GenerateGuidsNow="$(HarvestDirectoryGenerateGuidsNow)" 
        OutputFile="ProductFiles.wxs" 
        SuppressFragments="$(HarvestDirectorySuppressFragments)" 
        SuppressUniqueIds="$(HarvestDirectorySuppressUniqueIds)" 
        Transforms="Transforms.xsl" 
        ComponentGroupName="ProductFiles" 
        DirectoryRefId="INSTALLLOCATION" 
        KeepEmptyDirectories="false" 
        SuppressCom="%(HarvestDirectory.SuppressCom)" 
        SuppressRootDirectory="true" 
        SuppressRegistry="%(HarvestDirectory.SuppressRegistry)">
    </HeatDirectory>
 blah..
 </Target>
  <Target Name="AfterBuild">
blah..
  </Target>
</Project>

上面的代码创建了一个新的<SourceBinaries>元素,并将其设置为目录的路径。接下来,这个自定义的元素可以在.wixproj文件的其他部分使用作为变量。我们随后使用这个值填充SourceBinaries常量,该常量在.wxs文件中使用。
总之,在<HeatDirectory>元素中:
  • Directory属性的值来自于<SourceBinaries>
  • PreProcessorVariable属性的值来自于<DefineConstants>(或其他可用于.wxs文件的变量,如项目引用)

-1

2
很抱歉,我无法直接访问互联网链接来查看内容。请提供您要翻译的具体文本,我将尽力为您提供准确的汉语翻译。 - CSchulz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接