2011-11-07 44 views
10

我正在嘗試爲Windows服務創建一個WiX安裝程序,並且我已經讀過,我已將所有文件的keyPath設置爲「no」,使用我的WiX腳本中的.exe例外。 我在這裏使用Heat.exe目前我的生成目錄和文件結構是我的命令:WiX安裝程序:使用xslt和heat.exe來更新屬性

"$(WIX)bin\heat.exe" dir $(SolutionDir)EmailGenerationService\bin\PROD 
        -cg EmailGenFiles -gg -scom -sreg -sfrag -srd -suid 
        -dr INSTALLLOCATION -var var.FileSource 
        -t $(Projectdir)KeyPathTransform.xslt 
        -out $(ProjectDir)DirectoryAndFileComponents.wxs 

我打算更新我DirectoryAndFileComponents.wxs文件用的keyPath =」否」的所有文件中的元素。 從熱輸出的一個例子是:

<?xml version="1.0" encoding="utf-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
    <DirectoryRef Id="INSTALLLOCATION"> 
     <Component Id="Dollar.Common.dll" Guid="{2BCD0767-2383-47CF-B1BF-325FA4A3264F}"> 
     <File Id="Dollar.Common.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.dll" /> 
     </Component> 
     <Component Id="Dollar.Common.Exceptions.dll" Guid="{B7238091-76D1-42F5-A3B4-A539DFF3BD92}"> 
     <File Id="Dollar.Common.Exceptions.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Exceptions.dll" /> 
     </Component> 
     <Component Id="Dollar.Common.Exceptions.pdb" Guid="{43711979-747D-49C9-BAE4-ECD44FAF5E67}"> 
     <File Id="Dollar.Common.Exceptions.pdb" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Exceptions.pdb" /> 
     </Component> 
     <Component Id="Dollar.Common.Logging.dll" Guid="{59F9ABF3-5F68-410C-BC96-0556282F1E04}"> 
     <File Id="Dollar.Common.Logging.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Logging.dll" /> 
     </Component> 

這裏是我通過加熱來進行轉換的XSLT:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
      exclude-result-prefixes="msxsl" 
      xmlns:wix="http://schemas.microsoft.com/wix/2006/wix" 
      xmlns:my="my:my"> 

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

    <xsl:strip-space elements="*"/> 

    <xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match='/wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Component/wix:File[@Id and not (@Id="EmailGenerationService.exe")]'> 
    <xsl:attribute name="KeyPath"> 
      <xsl:value-of select="no"/> 
    </xsl:attribute> 
    </xsl:template> 
</xsl:stylesheet> 

我曾嘗試基於其他的這個相當多的變化在這個網站上的帖子和其他地方,但仍然無法獲得由heat.exe創建的文件的KeyPath =「no」。

我錯過了一些明顯的東西嗎?

回答

11

你有不同的定義的命名空間:

  1. 在XML:_ http://schemas.microsoft.com/wix/2006/wi
  2. 在XSLT:http://schemas.microsoft.com/wix/2006/wix

據我所知,對於WiX的正確的命名空間是http://schemas.microsoft.com/wix/2006/wi。所以你應該糾正你的XSLT。

XSLT:

<xsl:stylesheet version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
      exclude-result-prefixes="msxsl" 
      xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" 
      xmlns:my="my:my"> 

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

    <xsl:strip-space elements="*"/> 

    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match='wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Component/wix:File[@Id and not (@Id = "EmailGenerationService.exe")]'> 
     <xsl:copy> 
      <xsl:apply-templates select="@*"/> 
      <xsl:attribute name="KeyPath"> 
       <xsl:text>no</xsl:text> 
      </xsl:attribute> 
     </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

輸入XML:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
     <DirectoryRef Id="INSTALLLOCATION"> 
      <Component Id="Dollar.Common.dll" Guid="{2BCD0767-2383-47CF-B1BF-325FA4A3264F}"> 
       <File Id="Dollar.Common.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.dll" /> 
      </Component> 
      <Component Id="Dollar.Common.Exceptions.dll" Guid="{B7238091-76D1-42F5-A3B4-A539DFF3BD92}"> 
       <File Id="Dollar.Common.Exceptions.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Exceptions.dll" /> 
      </Component> 
      <Component Id="Dollar.Common.Exceptions.pdb" Guid="{43711979-747D-49C9-BAE4-ECD44FAF5E67}"> 
       <File Id="Dollar.Common.Exceptions.pdb" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Exceptions.pdb" /> 
      </Component> 
      <Component Id="Dollar.Common.Logging.dll" Guid="{59F9ABF3-5F68-410C-BC96-0556282F1E04}"> 
       <File Id="Dollar.Common.Logging.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Logging.dll" /> 
      </Component> 
     </DirectoryRef> 
    </Fragment> 
</Wix> 

輸出XML:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
    <DirectoryRef Id="INSTALLLOCATION"> 
     <Component Id="Dollar.Common.dll" Guid="{2BCD0767-2383-47CF-B1BF-325FA4A3264F}"> 
     <File Id="Dollar.Common.dll" Source="$(var.FileSource)\Dollar.Common.dll" KeyPath="no" /> 
     </Component> 
     <Component Id="Dollar.Common.Exceptions.dll" Guid="{B7238091-76D1-42F5-A3B4-A539DFF3BD92}"> 
     <File Id="Dollar.Common.Exceptions.dll" Source="$(var.FileSource)\Dollar.Common.Exceptions.dll" KeyPath="no" /> 
     </Component> 
     <Component Id="Dollar.Common.Exceptions.pdb" Guid="{43711979-747D-49C9-BAE4-ECD44FAF5E67}"> 
     <File Id="Dollar.Common.Exceptions.pdb" Source="$(var.FileSource)\Dollar.Common.Exceptions.pdb" KeyPath="no" /> 
     </Component> 
     <Component Id="Dollar.Common.Logging.dll" Guid="{59F9ABF3-5F68-410C-BC96-0556282F1E04}"> 
     <File Id="Dollar.Common.Logging.dll" Source="$(var.FileSource)\Dollar.Common.Logging.dll" KeyPath="no" /> 
     </Component> 
    </DirectoryRef> 
    </Fragment> 
</Wix> 
+0

謝謝你的迴應,但這也是行不通的。散熱運行正常,但出錯的結果仍然在所有節點上都有KeyPath =「yes」。 –

+0

@MarkJones,我已經更新了我的答案。 –

+1

完美,非常感謝你 –

2

我不會回答你原來的問題。 :)

我已閱讀,我NNED設置的keyPath爲「無」爲我的所有文件, 名爲.exe

的例外,我覺得你是誤導。在現實中,ServiceInstall table有一列Component_,並根據MSDN:

安裝使用InstallService表此服務,此組件的keyPath 必須是服務的可執行文件。

這並不意味着其他組件中的非EXE文件應該有@KeyPath='no'。它只是說服務的EXE文件應該駐留在一個單獨的組件中,並且必須是它的關鍵路徑。

關鍵路徑是MSI技術的一個非常重要的概念。你可以閱讀更多關於它here, see the description of the KeyPath column

現在,如果我們回到你原來的問題 - 不,你不必像你提到的那樣調整熱量輸出。它會默認生成您需要的WiX創作。

+0

感謝您的信息嚴,我從這裏拿我的假設:http://blog.tentaclesoftware.com/archive/2009/01/01/21.aspx –

+0

在示例中,您引用的單個組件包含一些文件。確實只有一個文件可以標記爲KeyPath ='yes',但是您不必將其他標記明確標記爲KeyPath ='no'。在爲你生成的heat.exe樣本中,你的假設是完全錯誤的。 –

+0

@Mark Jones,對不起,如果我以前的評論似乎表達了一種強硬的形式。當我看到人們花時間和努力去解決不存在的問題時,我簡直無法抗拒反應:) –

1

我可以提出一種不同的方法嗎?

<xsl:template match="@KeyPath[parent::wix:File[parent::wix:Component[parent::wix:DirectoryRef[parent::wix:Fragment[parent::wix:Wix]]]] and . != 'EmailGenerationService.exe']"> 
     <xsl:attribute name="KeyPath"> 
      <xsl:value-of select="'no'"/> 
     </xsl:attribute> 
</xsl:template> 

只是改變你的模板匹配到上面,你應該有正確的結果。