WiX 5中WixQuietExec执行失败问题排查求助
WiX 5执行DOS命令写入文件时DLL错误的解决方法
问题描述
编写了如下.wxs文件,试图通过DOS命令将文本写入文件,但安装时弹出错误:此Windows Installer程序包存在问题。无法运行完成此安装所需的DLL。
原代码:
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v5/wxs/util" > <Package Compressed="yes" InstallerVersion="500" Manufacturer="Acme" Name="Test" UpgradeCode="da08e63d-6cad-4941-a412-54457ef0c937" Version="1.0.0.0" > <Binary Id="WixUtilExtension" SourceFile="C:\Users\ak109755\.nuget\packages\wixtoolset.util.wixext\5.0.2\wixext5\WixToolset.Util.wixext.dll" /> <CustomAction BinaryRef="WixUtilExtension" DllEntry="WixQuietExec" Id="MessageBoxAction" Impersonate="no" Return="check" /> <DirectoryRef Id="AcmeDir"> <Component Id="InstallerExecutable" Guid="2addbefe-1b0a-4a19-8c75-e5fa0a359f44"> <CreateFolder/> </Component> </DirectoryRef> <Feature Id="MainApplication" Title="Main Application" Level="1"> <ComponentRef Id="InstallerExecutable"/> </Feature> <InstallExecuteSequence> <Custom Action="MessageBoxAction" Before="InstallFinalize" Condition="1"/> </InstallExecuteSequence> <MediaTemplate EmbedCab="yes"/> <Property Id="MessageBoxAction" Value="echo 'hey' >>c:\temp\hey.txt" /> <StandardDirectory Id="ProgramFiles64Folder"> <Directory Id="AcmeDir" Name="Acme"/> </StandardDirectory> </Package> </Wix>
问题原因
- 手动引用扩展DLL错误:WiX 5中使用
WixUtilExtension时,不需要手动添加<Binary>元素指向扩展DLL,扩展会自动处理嵌入,手动指定路径反而会导致DLL加载异常。 - 属性与动作ID重名:自定义动作ID
MessageBoxAction和传递命令的属性ID完全相同,这会导致Windows Installer解析时出现冲突。 - 命令行格式错误:Windows Installer中,重定向符号
>需要转义为^>,否则会被当作安装包的参数处理,而非DOS命令的一部分;另外直接使用c:\temp可能存在目录不存在或权限不足的问题。
修正后的代码
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v5/wxs/util" > <Package Compressed="yes" InstallerVersion="500" Manufacturer="Acme" Name="Test" UpgradeCode="da08e63d-6cad-4941-a412-54457ef0c937" Version="1.0.0.0" > <!-- 移除手动添加的Binary元素 --> <CustomAction BinaryRef="WixUtilExtension" DllEntry="WixQuietExec" Id="MessageBoxAction" Impersonate="no" Return="check" /> <DirectoryRef Id="AcmeDir"> <Component Id="InstallerExecutable" Guid="2addbefe-1b0a-4a19-8c75-e5fa0a359f44"> <CreateFolder/> </Component> </DirectoryRef> <Feature Id="MainApplication" Title="Main Application" Level="1"> <ComponentRef Id="InstallerExecutable"/> </Feature> <InstallExecuteSequence> <Custom Action="MessageBoxAction" Before="InstallFinalize" Condition="1"/> </InstallExecuteSequence> <MediaTemplate EmbedCab="yes"/> <!-- 重命名属性ID,避免与动作ID冲突,同时修正命令行转义 --> <Property Id="MessageBoxActionCmd" Value="echo hey ^>^> [Temp]hey.txt" /> <StandardDirectory Id="ProgramFiles64Folder"> <Directory Id="AcmeDir" Name="Acme"/> </StandardDirectory> </Package> </Wix>
关键修改说明
- 移除了手动指定的
<Binary>元素,让WiX自动处理扩展DLL的嵌入。 - 将传递命令的属性ID改为
MessageBoxActionCmd,与自定义动作IDMessageBoxAction区分开。 - 修正命令行:用
^>^>代替>>进行转义;使用[Temp]系统属性获取Windows临时目录,避免c:\temp不存在或权限问题;去掉了echo后的单引号,因为DOS中echo 'hey'会输出带引号的文本,若要输出纯文本直接写echo hey即可。
内容的提问来源于stack exchange,提问作者Andy King
相关产品推荐
相关产品推荐

