回滚自定义操作失败会怎样?是否需在Wix CustomAction中指定Return属性?
回滚自定义操作失败的行为及Return属性的作用
核心结论
Windows Installer在执行回滚自定义操作时,会自动忽略其错误返回值——即便你在WiX的CustomAction元素中设置了Return="check",回滚流程也不会因自定义操作失败而终止,错误会被系统转换为成功状态。
测试验证
通过以下测试可以验证这一行为:
- C++自定义操作代码:返回明确的失败错误码
UINT __stdcall ForceInstallFailure(MSIHANDLE hModule) { return ERROR_INSTALL_FAILURE; }
- WiX配置:设置
Return="check"并标记为回滚操作
<CustomAction Id="CA_ForceInstallFailure" BinaryKey="Bin_CAInst" DllEntry="ForceInstallFailure" Execute="rollback" Return="check" Impersonate="no" />
该配置生成的自定义操作类型为3329,由基础类型1(DLL入口点调用)加上3328(脚本内执行+无模拟+回滚标记)组成。
- MSI日志结果:
Rollback: CA_ForceInstallFailure MSI (s) (90:B4) [02:18:54:053]: Executing op: ActionStart(Name=CA_ForceInstallFailure,,) MSI (s) (90:B4) [02:18:54:053]: Executing op: CustomActionRollback(Action=CA_ForceInstallFailure,ActionType=3329,Source=BinaryData,Target=ForceInstallFailure,) MSI (s) (90:14) [02:18:54:053]: Invoking remote custom action. DLL: C:\Windows\Installer\MSIC523.tmp, Entrypoint: ForceInstallFailure CustomAction CA_ForceInstallFailure returned actual error code 1603 but will be translated to success due to continue marking
日志明确显示,自定义操作返回了1603错误,但系统自动将其转换为成功状态,并未中断回滚。
补充说明
这种行为逻辑上是合理的:回滚的目的是将系统恢复到安装前的状态,若因单个回滚步骤失败就终止整个流程,可能导致系统处于不一致的中间状态。但目前官方文档中对此行为的明确描述较为缺失。
内容的提问来源于stack exchange,提问作者andrebroz
相关产品推荐
相关产品推荐

