WIX安装程序中输入值无法传递至自定义动作问题
解决WIX对话框输入框值无法传递到Deferred自定义动作的问题
你的问题根源在于Windows Installer的属性作用域规则:只有公共属性(Property ID必须全大写)才能在UI序列和执行序列之间传递值。你当前定义的MyKeyStorePassword和MyTrustStorePassword是驼峰命名的私有属性,UI对话框中修改的值无法被带到后续的Deferred自定义动作中,所以始终使用初始值。
修改步骤:
- 修改Property定义为全大写ID:
<Property Id="MYKEYSTOREPASSWORD"/> <Property Id="MYTRUSTSTOREPASSWORD"/>
如果需要预填充值:
<Property Id="MYKEYSTOREPASSWORD" Value="1"/> <Property Id="MYTRUSTSTOREPASSWORD" Value="2"/>
- 更新对话框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>
- 更新自定义动作的参数传递:
<CustomAction Id="DummyCustomAction" BinaryKey="CommonCA" DllEntry="DummyCustomAction" Execute="deferred" Return="check" /> <CustomAction Id="DummyCustomActionProperties" Property="DummyCustomAction" Value="MYKEYSTOREPASSWORD=[MYKEYSTOREPASSWORD];MYTRUSTSTOREPASSWORD=[MYTRUSTSTOREPASSWORD]"/>
- 更新自定义动作代码中的读取键名:
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
相关产品推荐
相关产品推荐

