2

所以我可能做的不正确,但它是这样的:

我有一个引用 4 个 SQL Server 程序集的应用程序

应用程序必须针对 SQL 2008 和 2010 运行。

我让它工作的唯一方法是让我的应用程序为我的 SQL 程序集引用一个“通用”路径。然后在我的 MSBuild 项目中,我将 2008 程序集复制到“通用”文件夹并编译我的应用程序。我为 2012 年再次这样做。

我有一个像 Tools\Release\V2008 和 Tools\Release\V2010 这样的文件夹。这些文件夹包含所有的 EXE 和所需的 DLL(包括 4 个 sql server)。我对这些文件夹运行 HEAT。

但是,当我对每个文件夹运行 heat 时,每个文件夹都有相同的目录 ID 但不同的组件,我得到 2 个 wxs 文件,每个文件都有相同的文件(预期),但每个组件和文件 id 在 2 个 wxs 文件中都是相同的。

例子:

MSBuild Command:
    <Exec Command="&quot;$(WixTools)\heat.exe&quot; dir $(DeploymentRoot)\Tools\V2008 -dr TOOLS -cg Tools2008Component -var var.Tools2008Path -gg -scom -sreg -sfrag -srd  -o $(heatOutputPath)\cmp2008ToolsFrag.wxs"/>    

WXS File
    <DirectoryRef Id="TOOLS">
        <Component Id="cmp04831EC1F8BB21C028A7FC875720302F" Guid="*">
            <File Id="fil09727A8BFD32FDCE7C743D6DD2008E7C" KeyPath="yes" Source="$(var.Tools2008Path)\AL3Util.exe" />
        </Component>

MSBuild Command:
        <Exec Command="&quot;$(WixTools)\heat.exe&quot; dir $(DeploymentRoot)\Tools\V2012 -dr TOOLS -cg Tools2012Component -var var.Tools2012Path -gg -scom -sreg -sfrag -srd  -o $(heatOutputPath)\cmp2012ToolsFrag.wxs"/>

WXS file
    <DirectoryRef Id="TOOLS">
        <Component Id="cmp04831EC1F8BB21C028A7FC875720302F" Guid="*">
            <File Id="fil09727A8BFD32FDCE7C743D6DD2008E7C" KeyPath="yes" Source="$(var.Tools2012Path)\AL3Util.exe" />
        </Component>

如何让每个 WXS 文件具有唯一的组件和文件 ID?或者 - 我怎样才能做得更好:)

谢谢!

4

1 回答 1

7

ID 将是相同的,因为您使用的是-srd, 禁止根目录。在这种情况下,用于生成 ID 的路径将只是文件名,对于同名的文件生成相同的 ID。

您有两种选择:

1) 在执行 heat 以使用-t.

2) 收获后使用 XslTransform 任务 (.NET 4) 将 ID 重命名为 File_2012_AL3Util 和 File_2008_AL3Util。

您可以将此 XSL 应用于您的文件。在下面的示例中,如果元素匹配文件名的“MyFile”和目录 ID 的“MyID”,则该元素将被删除。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:wi="http://schemas.microsoft.com/wix/2006/wi">

  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

  <!-- Matches both directory name and file name. -->
  <!-- Matches any Component that has its @Directory with same @Id as Directory 'MyID'. -->
  <!-- Function ends-with does not work with heat. -->
  <xsl:template match="//wi:Component[@Directory=//wi:Directory[@Name='MyID']/@Id and substring(wi:File/@Source, string-length(wi:File/@Source) - string-length('MyFile') + 1) = 'MyFile']" />

</xsl:stylesheet>
于 2014-09-12T18:09:09.890 回答