Wix Toolset v4(5.0.0):含引用动作时覆盖StartServices标准动作失败
WiX v4中添加ScheduleReboot后触发WIX7009错误的解决方法
我尝试自定义StartServices标准动作,单独编译安装包可以成功执行,但添加ScheduleReboot引用动作后,编译失败并抛出WIX7009错误。项目是从WiX v3迁移到v4的,原动作序列在v3中可正常运行,示例代码如下:
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> <Package Name="WixTest" Version="1.0.0" Manufacturer="Any Company" UpgradeCode="{75393798-99D0-4342-BA82-D7CDE7DAA27F}"> <Feature Id="Feature" ConfigurableDirectory="INSTALLDIR" /> <!-- If the ScheduleReboot action is commented out the compile will succeed if uncommented, the compile will fail with: Error WIX7009 The action 'StartServices' conflicts with a virtual symbol with the same id. To override the virtual symbol (e.g., to reschedule a custom action), use the 'override' access modifier: 'override StartServices'. If you didn't intend to override a virtual symbol, use a different id to avoid the conflict. wixtest D:\save\wixtest\Product.wxs 21 --> <InstallExecuteSequence> <!-- <ScheduleReboot Before="StartServices" Condition="RESTART_REQUIRED=1" /> --> <StartServices Condition="RESTART_SERVICES=1" /> </InstallExecuteSequence> <StandardDirectory Id="ProgramFilesFolder" > <Directory Id="INSTALLDIR" Name="installHere"/> </StandardDirectory> </Package> </Wix>
问题原因
WiX v4的动作序列机制和v3存在差异:当你在序列中引用ScheduleReboot这类标准动作时,WiX会自动引入该动作所属的默认标准序列集,其中已经包含了默认的StartServices动作。此时你自定义的StartServices因未明确声明是覆盖默认动作,就会和默认序列里的同名动作产生冲突,触发WIX7009错误。而WiX v3不会自动引入这些依赖的标准动作序列,因此不会出现该问题。
解决方法
在自定义的StartServices元素前加上override关键字,明确告知WiX你要覆盖默认的虚拟动作,修改后的InstallExecuteSequence代码如下:
<InstallExecuteSequence> <ScheduleReboot Before="StartServices" Condition="RESTART_REQUIRED=1" /> <override StartServices Condition="RESTART_SERVICES=1" /> </InstallExecuteSequence>
这样编译时WiX会识别你是要替换默认的StartServices动作,即可避免冲突。
内容的提问来源于stack exchange,提问作者Bill Packard
相关产品推荐
相关产品推荐

