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

WIX安装程序中输入值无法传递至自定义动作问题

解决WIX对话框输入框值无法传递到Deferred自定义动作的问题

你的问题根源在于Windows Installer的属性作用域规则:只有公共属性(Property ID必须全大写)才能在UI序列和执行序列之间传递值。你当前定义的MyKeyStorePassword和MyTrustStorePassword是驼峰命名的私有属性,UI对话框中修改的值无法被带到后续的Deferred自定义动作中,所以始终使用初始值。

修改步骤:

  1. 修改Property定义为全大写ID:
<Property Id="MYKEYSTOREPASSWORD"/>
<Property Id="MYTRUSTSTOREPASSWORD"/> 

如果需要预填充值:

<Property Id="MYKEYSTOREPASSWORD" Value="1"/>
<Property Id="MYTRUSTSTOREPASSWORD" Value="2"/> 
  1. 更新对话框Control的Property绑定:
<Control Id="MyKeyStorePasswordLabel" Type="Text" X="20" Y="105" Width="100" Height="30" NoPrefix="yes" Text="MyKeyStorePassword" />
<Control Id="MyKeyStorePassword" Type="Edit" X="130" Y="105" Width="200" Height="18" Property="MYKEYSTOREPASSWORD" Text="MyKeyStorePassword" >
</Control>

<Control Id="MyTrustStorePasswordLabel" Type="Text" X="20" Y="125" Width="100" Height="30" NoPrefix="yes" Text="MyTrustStorePassword" />
<Control Id="MyTrustStorePassword" Type="Edit" X="130" Y="125" Width="200" Height="18" Property="MYTRUSTSTOREPASSWORD">
</Control>
  1. 更新自定义动作的参数传递:
<CustomAction Id="DummyCustomAction" BinaryKey="CommonCA" DllEntry="DummyCustomAction" Execute="deferred" Return="check" />
<CustomAction Id="DummyCustomActionProperties" Property="DummyCustomAction" Value="MYKEYSTOREPASSWORD=[MYKEYSTOREPASSWORD];MYTRUSTSTOREPASSWORD=[MYTRUSTSTOREPASSWORD]"/>
  1. 更新自定义动作代码中的读取键名:
public static ActionResult DummyCustomAction(Session session)
{
    var myKeyStorePassword = session.CustomActionData["MYKEYSTOREPASSWORD"];
    var myTrustStorePassword = session.CustomActionData["MYTRUSTSTOREPASSWORD"];
    session.Log($"MyKeyStorePassword is {myKeyStorePassword} and MyTrustStorePassword is {myTrustStorePassword}");
    return ActionResult.Success;
}

验证效果

修改后重新编译安装包:

  • 输入框预填充值会正常显示
  • 修改输入框内容后,自定义动作日志会输出你新输入的值,而不是初始值

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 12:25:25