You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WiX4自定义UI验证后直接进入服务器模式的问题排查

自定义WiX4对话框输入验证问题分析与解决

问题背景

使用WiX4(rc2、rc3及最新版本)实现自定义对话框的用户输入验证,配置了文件夹选择对话框和输入验证逻辑,但出现异常:当输入无效路径时,虽然弹出错误提示对话框,但关闭后安装直接进入服务器阶段,而非停留在原对话框让用户修正。

现有配置代码

文件夹选择对话框属性配置

<Publish Dialog="CustomPropertiesDlg" Control="ChangeFooFolder" Property="_BrowseProperty" Value="FOO_DIR" Order="1" />
<Publish Dialog="CustomPropertiesDlg" Control="ChangeFooFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2" />

下一步按钮验证逻辑配置

<Publish Dialog="CustomPropertiesDlg" Control="Next" Event="DoAction" Value="UI_CheckFooDir" Order="1" />
<Publish Dialog="CustomPropertiesDlg" Control="Next" Event="NewDialog" Value="InvalidFooPathDlg" Order="2" Condition="FOO_DIR_VALID&lt;&gt;&quot;1&quot;" />
<Publish Dialog="CustomPropertiesDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="5" Condition="FOO_DIR_VALID=&quot;1&quot;" />

<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="CustomPropertiesDlg" Order="10" />

自定义验证动作代码

[CustomAction]
public static ActionResult VerifyFooPath(Session session)
{
  session["FOO_DIR_VALID"] = "0";
  var fooDir= session["FOO_DIR"];
  session.Log($"Checking whether {fooDir} contains a foo.exe file");
  if (Directory.Exists(fooDir) && File.Exists(Path.Combine(fooDir, "foo.exe")))
  {
    session.Log($"Foo directory accepted as {fooDir}");
    session["FOO_DIR_VALID"] = "1";
  }
  return ActionResult.Success;
}

异常现象与日志信息

日志显示自定义动作已执行且正确设置FOO_DIR_VALID为"0",UI弹出“路径无效”对话框,但关闭后安装直接进入服务器阶段:

Action start 18:19:30: UI_CheckFooDir.
MSI (c) (F4:04) [18:19:30:414]: Invoking remote custom action. DLL: C:\Users\bla\AppData\Local\Temp\MSI5048.tmp, Entrypoint: VerifyFooPath
MSI (c) (F4:10) [18:19:30:415]: Cloaking enabled.
MSI (c) (F4:10) [18:19:30:415]: Attempting to enable all disabled privileges before calling Install on Server
MSI (c) (F4:10) [18:19:30:415]: Connected to service for CA interface.
MSI (c) (F4!C0) [18:19:30:876]: PROPERTY CHANGE: Adding FOO_DIR_VALID property. Its value is '0'.
Action ended 18:19:30: UI_CheckFooDir. Return value 1.
Action 18:19:30: InvalidFooPathDlg. Dialog created
Action ended 18:19:32: WelcomeDlg. Return value 1.
MSI (c) (F4:34) [18:19:32:623]: Skipping action: MaintenanceWelcomeDlg (condition is false)
MSI (c) (F4:34) [18:19:32:623]: Doing action: ProgressDlg
MSI (c) (F4:34) [18:19:32:623]: Note: 1: 2205 2:  3: ActionText 
Action 18:19:32: ProgressDlg. 
Action start 18:19:32: ProgressDlg.
Action 18:19:32: ProgressDlg. Dialog created
Action ended 18:19:32: ProgressDlg. Return value 1.
MSI (c) (F4:34) [18:19:32:729]: Doing action: ExecuteAction
MSI (c) (F4:34) [18:19:32:729]: Note: 1: 2205 2:  3: ActionText 
Action 18:19:32: ExecuteAction. 
Action start 18:19:32: ExecuteAction.
MSI (c) (F4:34) [18:19:32:735]: PROPERTY CHANGE: Adding SECONDSEQUENCE property. Its value is '1'.
MSI (c) (F4:34) [18:19:32:736]: Grabbed execution mutex.
MSI (c) (F4:34) [18:19:32:736]: Incrementing counter to disable shutdown. Counter after increment: 0
MSI (c) (F4:34) [18:19:32:736]: Switching to server: (snipped properties here)

问题根源与解决方案

问题根源

当使用NewDialog打开InvalidFooPathDlg后,该对话框默认关闭时不会自动返回原输入对话框,而是让MSI继续执行后续的UI序列,最终进入安装执行阶段。

解决方案

给InvalidFooPathDlg的OK按钮添加发布事件,指定关闭后返回CustomPropertiesDlg,让用户可以修正输入:

<!-- 给InvalidFooPathDlg的OK按钮添加返回逻辑 -->
<Publish Dialog="InvalidFooPathDlg" Control="OK" Event="NewDialog" Value="CustomPropertiesDlg" Order="1" />

额外注意事项

  • 确保InvalidFooPathDlg的所有关闭控件(如OK按钮)都配置了返回原对话框的逻辑,避免遗漏
  • 确认自定义动作UI_CheckFooDir为即时模式(Immediate),保证在UI阶段执行验证(当前配置已满足)

内容的提问来源于stack exchange,提问作者Benjamin Podszun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 07:57:06