我正在关注多个来源/SO 帖子,甚至是 Wix 安装程序书籍,这就是我目前在立即自定义操作中设置两个属性然后尝试在延迟操作中读取它的方式。但是,它不起作用(失败并回滚)并且我不断收到System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键。在我的日志中
这是我的 .wxs 文件的一部分:
<!-- Custom Actions -->
<!-- Reference library for custom actions-->
<Binary Id="myCustomActions" SourceFile="$...something.CA.dll"/>
<!-- Set my properties that will be passed on to InsertPluginData as its a deferred CA and not able to read properties -->
<CustomAction
Id="CA_SetProperties"
BinaryKey="myCustomActions"
DllEntry="SetProperties"
Execute="immediate"
/>
<!-- This modifies the CSI File to insert the plugin into the interface -->
<!-- Eliminates the user having to do this manually -->
<CustomAction
Id="CA_InsertPluginData"
BinaryKey="myCustomActions"
DllEntry="InsertPluginData"
Execute="deferred"
Return="check"
/>
<!-- Custom Actions Sequence -->
<InstallExecuteSequence>
<Custom Action="CA_SetProperties" After="InstallInitialize" />
<Custom Action="CA_InsertPluginData" Before="InstallFinalize"/>
</InstallExecuteSequence>
我的 CustomActions.cs:
[CustomAction]
public static ActionResult SetProperties(Session session)
{
session.Log("Begin SetProperties");
CustomActionData data = new CustomActionData();
data["Test"] = "1";
session["InsertPluginData"] = data.ToString();
session.Log("End SetProperties");
return ActionResult.Success;
}
[CustomAction]
public static ActionResult InsertPluginData(Session session)
{
session.Log("Begin InsertPluginData");
CustomActionData data = session.CustomActionData;
string property1 = data["Test"];
session.Log("Begin InsertPluginData: Test" + property1);
return ActionResult.Success;
}
为了确认我的立即行动正在发生,我在登录时运行了它:
开始设置属性
MSI (s) (D4!EC) [10:30:17:941]:属性更改:添加 InsertPluginData 属性。它的值为'Test=1'。
结束设置属性