2012-01-05 39 views
6

我讨厌几乎复制现有的问题,但所提供的答案都没有奏效:如何从热收获(WiX)中排除SVN文件?

这里是我的.wxs是什么样子:

<?xml version="1.0" encoding="utf-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
<Fragment> 
<DirectoryRef Id="SDKCONTENTDIR"> 
<Directory Id="dirE2EC21E8B765C611E918FB22F30721D1" Name=".svn" /> 
<Directory Id="dir7DC42F44E7FE9E20277B180A353D0263" Name="bin" /> 
</DirectoryRef> 
</Fragment> 
<Fragment> 
<ComponentGroup Id="sdkContent"> 
<Component Id="cmp5E86312F0CA2C53B8173AECD6A428747" Directory="dirE2EC21E8B765C611E918FB22F30721D1" Guid="{E87F312D-9DA2-4A68-B6C5-BCE2FF90720C}"> 
<File Id="filB766A28A7577EB4311FD03CD707BC211" KeyPath="yes" Source="$(var.publishContentDir)\.svn\all-wcprops" /> 
</Component> 
<Component Id="cmp6EF52B3E331F226299060D45F533DC07" Directory="dirE2EC21E8B765C611E918FB22F30721D1" Guid="{5EA6AB2D-20C3-4B07-8E0A-7C28135BE922}"> 
<File Id="fil83205196F05211A66F9D25A7A5496FBA" KeyPath="yes" Source="$(var.publishContentDir)\.svn\entries" /> 
</Component> 

...

我用这的.xsl代码排除:

<xsl:key name="svn-search" match="wix:Component[ancestor::wix:Directory/@Name = '.svn']" use="@Id" /> 
<xsl:template match="wix:Directory[@Name='.svn']" /> 
<xsl:template match="wix:Component[key('svn-search', @Id)]" /> 

但我发现了许多“错误48未解决的参考符号”的错误为不删除所有子元素。

想法?

回答

4

这是我得到了什么工作:

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

    <!-- Copy all attributes and elements to the output. --> 
    <xsl:template match="@*|*"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*" /> 
      <xsl:apply-templates select="*" /> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:output method="xml" indent="yes" /> 

    <!-- Create searches for the directories to remove. --> 
    <xsl:key name="svn-search" match="wix:Directory[@Name = '.svn']" use="@Id" /> 
    <xsl:key name="tmp-search" match="wix:Directory[@Name = 'tmp']" use="@Id" /> 
    <xsl:key name="prop-base-search" match="wix:Directory[@Name = 'prop-base']" use="@Id" /> 
    <xsl:key name="text-base-search" match="wix:Directory[@Name = 'text-base']" use="@Id" /> 
    <xsl:key name="props-search" match="wix:Directory[@Name = 'props']" use="@Id" /> 

    <!-- Remove directories. --> 
    <xsl:template match="wix:Directory[@Name='.svn']" /> 
    <xsl:template match="wix:Directory[@Name='props']" /> 
    <xsl:template match="wix:Directory[@Name='tmp']" /> 
    <xsl:template match="wix:Directory[@Name='prop-base']" /> 
    <xsl:template match="wix:Directory[@Name='text-base']" /> 

    <!-- Remove Components referencing those directories. --> 
    <xsl:template match="wix:Component[key('svn-search', @Directory)]" /> 
    <xsl:template match="wix:Component[key('props-search', @Directory)]" /> 
    <xsl:template match="wix:Component[key('tmp-search', @Directory)]" /> 
    <xsl:template match="wix:Component[key('prop-base-search', @Directory)]" /> 
    <xsl:template match="wix:Component[key('text-base-search', @Directory)]" /> 

    <!-- Remove DirectoryRefs (and their parent Fragments) referencing those directories. --> 
    <xsl:template match="wix:Fragment[wix:DirectoryRef[key('svn-search', @Id)]]" /> 
    <xsl:template match="wix:Fragment[wix:DirectoryRef[key('props-search', @Id)]]" /> 
    <xsl:template match="wix:Fragment[wix:DirectoryRef[key('tmp-search', @Id)]]" /> 
    <xsl:template match="wix:Fragment[wix:DirectoryRef[key('prop-base-search', @Id)]]" /> 
    <xsl:template match="wix:Fragment[wix:DirectoryRef[key('text-base-search', @Id)]]" /> 
</xsl:stylesheet> 
+2

当在.svn下有子目录时,我遇到了解决方案问题。此外ComponentRefs不会被删除。 – tofutim 2012-04-24 09:06:31

0

由于您滤除了组件元素,而是保留了ComponentRef元素,所以会出现“未解决的符号”错误。因此,这些元素保持孤立并引用缺少的组件元素。这被WiX编译器捕获。

正如您现在可能已经猜到的那样,也要过滤掉相应的ComponentRef元素。希望这可以帮助。

+0

是的,有孤儿的元素,但问题是,我不能找出一种方法来过滤它们。 Heat的.wxs中没有ComponentRef元素。事实上,自顶层.svn目录被过滤掉以后,组件元素就会成为孤儿。 svn-search似乎没有正常工作,但我无法确定原因。 – jbierling 2012-01-06 03:28:28

19

我有同样的问题,发现你的答案。但是,我不满意是否需要按名称指定.svn文件夹的子目录。如果将来.svn目录改变了结构,或者如果我有一个名为tmp的目录,这可能会中断...

当我对xml运行xsl时,我还注意到有一些目录片段分散周围。作为强迫症,并希望清理,我注意到heat.exe有一个“压制碎片”的选项。实际效果是使Directory标签实际上嵌套在一起,这使得编写xsl文件变得更容易。

从嵌套标签结构中删除.svn目录后,我仍然遇到ComponentRefs指向组件ID的问题,这些组件ID已被删除,并且包含它们的包含目录。作为xsl noob我自己,我不得不做一点挖掘,但发现我可以在xsl:key的use属性中使用“descendant ::”。

总之,这里是我的解决方案。请注意,我还没有尝试过使用它来构建MSI;这将在一两天内出现。但即使是不完美的,至少这可能帮助别人同样的问题...

用途:heat.exe DIR源-t excludesvn.xsl -sfrag -o files.wxs

<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"> 
    <!-- Copy all attributes and elements to the output. --> 
    <xsl:template match="@*|*"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*" /> 
     <xsl:apply-templates select="*" /> 
    </xsl:copy> 
    </xsl:template> 
    <xsl:output method="xml" indent="yes" /> 

    <!-- Search directories for the components that will be removed. --> 
    <xsl:key name="svn-search" match="wix:Directory[@Name = '.svn']" use="descendant::wix:Component/@Id" /> 

    <!-- Remove directories. --> 
    <xsl:template match="wix:Directory[@Name='.svn']" /> 

    <!-- Remove componentsrefs referencing components in those directories. --> 
    <xsl:template match="wix:ComponentRef[key('svn-search', @Id)]" /> 
</xsl:stylesheet> 
+1

哇,对于“noob”这是很好的,尤其是使用'svn-search'键。好样的!哦,''与您的两个显式的'apply-templates'行相同。 – 2012-02-09 22:39:12

+1

解决方案是正确的。 -sfrag是关键。 – tofutim 2012-04-24 09:11:22

+0

对于'svn-search'键,你也可以使用''。此XPath将wix:Component与名为'.svn'的wix:Directory祖先匹配。有关更多信息,请参见[XPath语法](http://msdn.microsoft.com/zh-cn/library/ms256471(v = vs.85).aspx)。 – MageWind 2013-10-08 14:44:01

相关问题