如何使用Wix v4 Heat Harvesting为采集程序创建快捷方式?
解决Wix v4中为Heat采集的EXE添加快捷方式的问题
错误原因分析
你遇到的Target与Advertise不能同时指定错误,是因为广告快捷方式(Advertise='yes')不需要手动指定Target。广告快捷方式依赖于所属组件的关联关系,而非直接指向文件路径,因此两者不能共存。
下面提供两种可行的解决方案,根据你的需求选择:
方案1:使用非广告快捷方式(推荐,简单易维护)
这种方式适合大多数常规安装场景,直接创建指向EXE的普通快捷方式:
修改Package.wxs中的ShortcutsSetup组件,去掉Advertise='yes',并使用Windows Installer的文件引用语法[#App.exe]指向采集的EXE文件:
<Component Id="ShortcutsSetup" Directory="INSTALLFOLDER" Guid="{Your-Guid-Here}"> <!-- 开始菜单快捷方式 --> <Shortcut Id="StartMenuShortcut" Directory="StartMenuFolder" Target="[#App.exe]" Name="App 1.0.0.0" WorkingDirectory="INSTALLFOLDER"/> <!-- 桌面快捷方式 --> <Shortcut Id="DesktopShortcut" Directory="DesktopFolder" Target="[#App.exe]" Name="App 1.0.0.0" WorkingDirectory="INSTALLFOLDER"/> <!-- 确保卸载时删除快捷方式 --> <RemoveFile Id="RemoveStartMenuShortcut" Directory="StartMenuFolder" Name="App 1.0.0.0.lnk" On="uninstall"/> <RemoveFile Id="RemoveDesktopShortcut" Directory="DesktopFolder" Name="App 1.0.0.0.lnk" On="uninstall"/> </Component>
注意:
[#App.exe]中的App.exe需要和Heat采集生成的.wxs文件中,对应EXE的<File>元素的Id一致。如果Heat自动生成了类似filABC123的随机ID,需要替换为实际ID。
方案2:使用广告快捷方式(适合需要修复/广告功能的场景)
广告快捷方式需与EXE所在的组件绑定,因此需要通过XSL转换修改Heat的采集输出,自动为EXE组件添加快捷方式:
- 创建
HeatTransform.xsl转换文件:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wix="http://wixtoolset.org/schemas/v4/wxs"> <xsl:output method="xml" indent="yes"/> <!-- 匹配目标EXE文件,为其所在组件添加广告快捷方式 --> <xsl:template match="wix:File[@Source='../harvestDirectory/App.exe']"> <xsl:copy> <xsl:apply-templates select="@*"/> <!-- 开始菜单广告快捷方式 --> <wix:Shortcut Id="StartMenuShortcut" Directory="StartMenuFolder" Name="App 1.0.0.0" Advertise="yes" WorkingDirectory="INSTALLFOLDER"/> <!-- 桌面广告快捷方式 --> <wix:Shortcut Id="DesktopShortcut" Directory="DesktopFolder" Name="App 1.0.0.0" Advertise="yes" WorkingDirectory="INSTALLFOLDER"/> </xsl:copy> </xsl:template> <!-- 保留其他所有元素不变 --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
- 在
.wixproj的HarvestDirectory节点中添加转换引用:
<HarvestDirectory Include="../harvestDirectory/"> <ComponentGroupName>HarvestedComponents</ComponentGroupName> <DirectoryRefId>INSTALLFOLDER</DirectoryRefId> <SuppressRootDirectory>true</SuppressRootDirectory> <Transform>HeatTransform.xsl</Transform> <!-- 新增此行 --> </HarvestDirectory>
- 最后删除
Package.wxs中单独的ShortcutsSetup组件及引用,因为快捷方式已经被集成到EXE的组件中。
内容的提问来源于stack exchange,提问作者jhkrum
相关产品推荐
相关产品推荐

