访问延迟操作中通过在立即操作中设置属性:字典中未找到给定的键。

huangapple go评论59阅读模式
英文:

Wix: Accessing properties in a deferred action by setting them in an immediate action: The given key was not present in the dictionary

问题

以下是您提供的文本的翻译部分:

我正在关注几个来源/SO帖子,甚至Wix安装程序书籍,这是我当前在即时自定义操作中设置两个属性,然后尝试在延迟操作中读取它。然而,它不起作用(失败并回滚),并且我一直收到日志中的 System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

这是我的.wxs文件的一部分:

<!-- 自定义操作 -->
<!-- 用于自定义操作的库的引用-->
<Binary Id="myCustomActions" SourceFile="$...something.CA.dll"/>

<!-- 设置将传递给InsertPluginData的我的属性,因为它是延迟CA,不能读取属性 -->
<CustomAction
  Id="CA_SetProperties"
  BinaryKey="myCustomActions"
  DllEntry="SetProperties"
  Execute="immediate"
  />

<!-- 这会修改CSI文件以将插件插入接口中 -->
<!-- 消除了用户手动执行此操作的需求 -->
<CustomAction
  Id="CA_InsertPluginData"
  BinaryKey="myCustomActions"
  DllEntry="InsertPluginData"
  Execute="deferred"
  Return="check"
  />

<!-- 自定义操作序列 -->
<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;
    }

为了确认我的即时操作是否正在运行,我启用了日志记录:

Begin SetProperties

MSI (s) (D4!EC) [10:30:17:941]: PROPERTY CHANGE: Adding InsertPluginData property. Its value is 'Test=1'.

End SetProperties

英文:

I am following several sources/SO posts and even the Wix installer book and this is how I am currently setting two properties in an immediate custom action then trying to read it in a deferred action. However, its not working (fails and goes to roll back) and I keep getting System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. in my log.

Here is a portion of my .wxs file:

<!-- 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>

My 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;
    }

To confirm my immediate action is happening I ran it with logging on:

Begin SetProperties

MSI (s) (D4!EC) [10:30:17:941]: PROPERTY CHANGE: Adding InsertPluginData property. Its value is 'Test=1'.

End SetProperties

答案1

得分: 0

请查找这些样本以解决您的需求,希望这能解决您的特定问题。还要提到这个WiX链接和资源的广告清单

请在GitHub上找到这些延迟模式C#自定义操作的示例:

DTF示例使用了我从未在实际软件包中使用过的方法。这只是一种免责声明。它似乎运行良好,并且使用了比第一个示例更高级的构造(第一个示例是手动执行操作)。

类似的回答: 请浏览以下两个答案以获取有关延迟模式自定义操作的更多详细信息(我认为没有必要重新编写这个):

自定义操作:


链接:

英文:

I think I will just point you to some samples for what you need and hope that this resolves your specific problems. Also want to mention this ad-how list of WiX links and resources.

Please find these samples for deferred mode C# custom actions on github:

The DTF sample uses an approach that I have never used in a live package. Just a disclaimer. It seems to work well and uses more advanced constructs than the first sample (which does things "manually").

Similar Answers: Please skim the following two answers for more details on deferred mode custom actions (I don't think there is any point rewriting this):

Custom Actions:


Links:

答案2

得分: 0

我通过修改SetProperties中的这一行来修复了它,将session["InsertPluginData"] = data.ToString();修改为session["CA_InsertPluginData"] = data.ToString();。关键在于会话中的字符串要与.wxs文件中设置的CustomAction Id匹配!

英文:

I fixed it by modifying this line in SetProperties session["InsertPluginData"] = data.ToString(); to session["CA_InsertPluginData"] = data.ToString(). The key here is for the string inside the session to match the CustomAction Id set in .wxs file!

huangapple
  • 本文由 发表于 2023年2月23日 23:33:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546975.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定