[英]WiX Installer: using xslt with heat.exe to update attributes
我正在嘗試為 Windows 服務創建 WiX 安裝程序,並且我讀到我需要將所有文件的 KeyPath 設置為“no”,但 WiX 腳本中的 .exe 除外。 我目前正在使用 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=”no”
所有文件元素。 熱量輸出的示例是:
<?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>
這是我傳遞給 heat 以執行轉換的 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”。
我錯過了一些明顯的東西嗎?
您有兩個不同的定義命名空間:
http://schemas.microsoft.com/wix/2006/wi
: http://schemas.microsoft.com/wix/2006/wi
http://schemas.microsoft.com/wix/2006/wix
: 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>
我不會回答你原來的問題。 :)
我已經讀到我必須將所有文件的 keyPath 設置為“no”,但 .exe 除外
我認為你被誤導了。 實際上ServiceInstall 表有一列Component_
,根據 MSDN:
要使用 InstallService 表安裝此服務,此組件的 KeyPath 必須是該服務的可執行文件。
這並不意味着其他組件中的非 exe 文件應該有@KeyPath='no'
。 它只是說服務的 EXE 文件應該駐留在一個單獨的組件中,並且必須是它的關鍵路徑。
關鍵路徑是MSI技術的一個非常重要的概念。 您可以在此處閱讀有關它的更多信息,請參閱 KeyPath 列的說明。
現在,如果我們回到您最初的問題 - 不,您不必按照您提到的方式調整熱量輸出。 默認情況下,它將生成您需要的 WiX 創作。
我可以建議一種不同的方法嗎?
<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>
只需將您的模板匹配更改為上述內容,您就會得到正確的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.