如何使用WiX将CustomActionData传递给CustomAction? [英] How to pass CustomActionData to a CustomAction using WiX?

查看:57
本文介绍了如何使用WiX将CustomActionData传递给CustomAction?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 CustomActionData上设置属性要通过延迟的自定义操作检索?

How are properties set on CustomActionData to be retrieved by a deferred custom action?

推荐答案

延迟的自定义操作不能直接访问安装程序属性(参考)。实际上,只有 CustomActionData 属性

Deferred custom actions can not directly access installer properties (reference). In fact, only CustomActionData property

session.CustomActionData

以及此处在会话对象上可用。

and other methods and properties listed here are available on the session object.

因此,对于延迟的自定义操作来说,要检索诸如 INSTALLLOCATION 之类的属性,您必须使用51型自定义操作(即set-property自定义操作)来传递这些信息,您将通过 session.CustomActionData 使用CustomAction的C#代码中的数据。 (请参阅参考& 参考

Therefore, for a deferred custom action to retrieve a property such as the INSTALLLOCATION, you have to use a type 51 custom action — i.e. a set-property custom action — to pass that information along and you'll consume the data from the CustomAction's C# code through session.CustomActionData. (see reference & reference)

以下是类型51自定义操作( CustomAction1 )的示例,该操作将设置可在中检索的属性CustomAction2

Below is an example of a type 51 custom action (CustomAction1) that will set a property that can be retrieved in CustomAction2.

<CustomAction Id="CustomAction1"
              Property="CustomAction2"
              Value="SomeCustomActionDataKey=[INSTALLLOCATION]"
/>

请注意,属性属性名称为 CustomAction2 。这个很重要。 类型为51的操作的Property属性值必须与使用 CustomActionData 的自定义操作的名称相同/相同。(请参见参考

Notice that Property attribute name is CustomAction2. This is important. The Property attribute's value of the type 51 action must be equal/identical to the name of the custom action that is consuming CustomActionData. (see reference)

是否注意到 Value 属性键/值对中的名称 SomeCustomActionDataKey ?在使用自定义操作( CustomAction2 )的C#代码中,您将通过 CustomActionData 查找该属性使用以下表达式:

Notice the name SomeCustomActionDataKey in the Value attribute key/value pair? In your C# code in the consuming custom action (CustomAction2), you'll look-up that property from CustomActionData by using the following expression:

string somedata = session.CustomActionData["SomeCustomActionDataKey"];

用于从 CustomActionData 不是类型51自定义操作的属性属性中的值,而是 key = value Value 属性中的对。 (重要的要点: CustomActionData 通过设置安装程序属性来填充,该属性的名称与使用自定义操作的ID相同,但 CustomActionData 键不是安装程序属性。)(请参阅引用

The key that you use to retrieve the value from CustomActionData is NOT the value in Property attribute of the type 51 custom action, but the key from the key=value pair in the Value attribute. (Important takeaway: CustomActionData is populated by setting an installer property that has the same name as the Id of the consuming custom action, but CustomActionData keys are NOT installer properties.) (see reference)

在我们的场景中,消费自定义操作是一个延迟的自定义操作,定义如下:

In our scenario the consuming custom action is a deferred custom action defined somewhat like the below:

<Binary Id="SomeIdForYourBinary" SourceFile="SomePathToYourDll" />
<CustomAction Id="CustomAction2"
              BinaryKey="SomeIdForYourBinary"
              DllEntry="YourCustomActionMethodName"
              Execute="deferred"
              Return="check"
              HideTarget="no"
/>

配置InstallExecuteSequence

当然,消费自定义操作( CustomAction2 )必须在51类自定义操作( CustomAction1 )。因此,您必须像这样安排它们:

Of course, the consuming custom action (CustomAction2) must run after the type 51 custom action (CustomAction1). So you'll have to schedule them like this:

<InstallExecuteSequence>
  <!--Schedule the execution of the custom actions in the install sequence.-->
  <Custom Action="CustomAction1" Before="CustomAction2" />
  <Custom Action="CustomAction2" After="[SomeInstallerAction]" />      
</InstallExecuteSequence>

这篇关于如何使用WiX将CustomActionData传递给CustomAction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆