Msbuild Wix/Heat:通道<;项目参考>;wixproj文件内部

Msbuild Wix/Heat:通道<;项目参考>;wixproj文件内部,msbuild,wix,heat,wix3.9,Msbuild,Wix,Heat,Wix3.9,我正在installer.wixproj中作为预构建事件运行heat命令。 我希望我的dir-参数(HarvestPath)成为包含的项目参考的目标目录 现在在我的.wixproj文件中 <PropertyGroup> <HarvestPath Condition=" '$(HarvestPath)' == '' ">"@(ProjectReference.TargetDir)"</HarvestPath> <DefineConstants>

我正在installer.wixproj中作为预构建事件运行heat命令。 我希望我的
dir
-参数(
HarvestPath
)成为包含的项目参考的目标目录

现在在我的.wixproj文件中

<PropertyGroup>
  <HarvestPath Condition=" '$(HarvestPath)' == '' ">"@(ProjectReference.TargetDir)"</HarvestPath>
  <DefineConstants>HarvestPath=$(HarvestPath)</DefineConstants>
</PropertyGroup>

<ProjectReference Include="..\..\NAME.csproj">
  <Name>NAME</Name>
  <Project>SOME_GUID</Project>
  <Private>True</Private>
  <DoNotHarvest>True</DoNotHarvest>
  <RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
  <RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>

“@(ProjectReference.TargetDir)”
HarvestPath=$(HarvestPath)
名称
一些
真的
真的
二进制文件;内容;卫星
安装文件夹
如何访问项目引用的目标目录?
“@(ProjectReference)”
只提供其.csproj文件的完整路径,我找不到任何相关文档。

好的,因此我找到了一个解决方法,以防有人感兴趣。
我只是简单地使用了
“$(SolutionDir)\MY\u PROJECT\u FOLDER\MY\u PROJECT\u TARGET”
。这并不完全是我的目标,但它很有效。

我找到了一种更可靠的方法,尽管有点复杂。我必须这样做,以支持使用较新的构建模板(GitTemplate.12.xaml)在TFS构建服务器上构建,因为:

  • 生成实际上不会写入项目中指定的
    OutputPath
    (例如bin\Release\AnyCPU),而是写入自己的生成输出文件夹
  • 生成会写入
    中间输出路径
    (例如obj\Release\AnyCPU),但不会复制heat.exe需要的依赖项
通过查找项目输出的实际去向(
\u GatheredProjectReferencePath
),wix2010.targets可以方便地通过。它将相关信息收集到一个项目集合(
COMProjects
)中,
HeatCOMProjects
目标循环到该集合中

您需要用正在加热的代码项目的名称替换“ACME.Core”、“ACME.Data”等,并确保WiX项目引用它们。您还需要确保HeatFile命令具有正确的参数,特别是
DirectoryRefId
,我认为需要指出DLL将安装在目标系统上的位置

<!-- Find where the .dll and .tlb files of source projects were written to.
     Can't rely on relative paths like "$(ProjectDir)..\..\ACME\ACME.Core\bin\$(ConfigurationName)\AnyCPU\ACME.Core.dll"
     because some build templates don't actually write to OutputPath.  Can't rely on the intermediate output path either
     (obj\...) because Heat needs to be able to find dependencies of any DLLs given. -->
<Target Name="GetCOMProjects" DependsOnTargets="ResolveProjectReferences">
  <ItemGroup>
    <COMProjects Include="%(_GatheredProjectReferencePaths.Name)"
                 Condition="%(_GatheredProjectReferencePaths.Name) == 'ACME.Core' Or
                            %(_GatheredProjectReferencePaths.Name) == 'ACME.Data' ">
      <Name>%(_GatheredProjectReferencePaths.Name)</Name>
      <DLLPath>%(_GatheredProjectReferencePaths.FullPath)</DLLPath>
      <TLBPath>$([System.IO.Path]::GetDirectoryName(%(_GatheredProjectReferencePaths.FullPath)))\%(_GatheredProjectReferencePaths.Filename).tlb</TLBPath>
    </COMProjects>
  </ItemGroup>
</Target>

<!-- Loop through each COMProjects item -->
<Target Name="HeatCOMProjects"
        Inputs="%(COMProjects.DLLPath); %(COMProjects.TLBPath)"
        Outputs="$(ProjectDir)%(COMProjects.Name).REGASM.wxs; $(ProjectDir)%(COMProjects.Name).REGTLB.wxs">
  <HeatFile
    ToolPath="$(WixToolPath)"
    File="%(COMProjects.DLLPath)"
    OutputFile="$(ProjectDir)%(COMProjects.Name).REGASM.wxs"
    GenerateGuidsNow="true"
    NoLogo="true"
    ComponentGroupName="%(COMProjects.Name).REGASM"
    DirectoryRefId="INSTALLDIR"
    SuppressRootDirectory="true"
    PreprocessorVariable="var.%(COMProjects.Name).TargetDir"
  />
  <HeatFile
    ToolPath="$(WixToolPath)"
    File="%(COMProjects.TLBPath)"
    OutputFile="$(ProjectDir)%(COMProjects.Name).REGTLB.wxs"
    GenerateGuidsNow="true"
    NoLogo="true"
    ComponentGroupName="%(COMProjects.Name).REGTLB"
    DirectoryRefId="INSTALLDIR"
    SuppressRootDirectory="true"
    PreprocessorVariable="var.%(COMProjects.Name).TargetDir"
  />
</Target>

<!-- Run Heat after building dependencies, but before building this project. -->
<Target Name="AfterResolveReferences" DependsOnTargets="GetCOMProjects; HeatCOMProjects" />

%(_GatheredProjectReferencePath.Name)
%(\u GatheredProjectReferencePath.FullPath)
$([System.IO.Path]::GetDirectoryName(%(\u GatheredProjectReferencePath.FullPath))\%(\u GatheredProjectReferencePath.Filename)。tlb