2012-01-05 40 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

相關問題