如何在 CustomActionData 上设置属性以便通过延迟的自定义操作检索?
如何在 CustomActionData 上设置属性以便通过延迟的自定义操作检索?
延迟自定义操作无法直接访问安装程序属性(参考文献)。事实上,只有CustomActionData
属性。
session.CustomActionData
在会话对象上,还有其他方法和属性,可以在此处列出。
因此,如果想要使用延迟的自定义操作检索属性(例如INSTALLLOCATION
),您必须使用类型 51 自定义操作(即设置属性自定义操作)来传递信息,然后通过session.CustomActionData
从 CustomAction 的 C# 代码中消耗数据(参见参考和参考)。
以下是一个类型 51 自定义操作的示例(CustomAction1
),它将设置一个属性,在CustomAction2
中可以检索该属性。
<CustomAction Id="CustomAction1"
Property="CustomAction2"
Value="SomeCustomActionDataKey=[INSTALLLOCATION]"
/>
请注意Property
属性名称为CustomAction2
。这很重要。类型为51的操作的Property
属性值必须等同于正在消费CustomActionData
的自定义操作的名称。(参见参考资料)
请注意Value
属性键/值对中的名称SomeCustomActionDataKey
。在您的C#代码中,消费自定义操作(CustomAction2
)将使用以下表达式从CustomActionData
查找该属性:
string somedata = session.CustomActionData["SomeCustomActionDataKey"];
Retrieving values from `CustomActionData` requires using the key from the `key=value` pair in the `Value` attribute, not the value in the `Property` attribute of the type 51 custom action. It's important to note that although `CustomActionData` is populated by setting an installer property with the same name as the Id of the consuming custom action, the keys in `CustomActionData` are not installer properties. See this reference for more information.<Binary Id="SomeIdForYourBinary" SourceFile="SomePathToYourDll" />
<CustomAction Id="CustomAction2"
BinaryKey="SomeIdForYourBinary"
DllEntry="YourCustomActionMethodName"
Execute="deferred"
Return="check"
HideTarget="no"
/>
配置InstallExecuteSequence
当然,在类型51的自定义操作(CustomAction1
)之后,消费自定义操作(CustomAction2
)必须运行。因此,您需要按照以下方式安排它们的计划:
<InstallExecuteSequence>
<!--Schedule the execution of the custom actions in the install sequence.-->
<Custom Action="CustomAction1" Before="CustomAction2" />
<Custom Action="CustomAction2" After="[SomeInstallerAction]" />
</InstallExecuteSequence>
Value="ActionDataKey1=Value1;ActionDataKey2=Value2"
。 - Marco Ciambronesession.CustomActionData.ToString()
读取它。 - rustyx对于我们这些C++菜鸟,您可以按如下方式检索属性:
MsiGetProperty(hInstall, "CustomActionData", buf, &buflen);
然后解析“buf”。感谢Bondbhai。
<SetProperty Id="CustomAction1" Before="CustomAction1" Value="data" Sequence="execute"/>
<CustomAction Id="CustomAction1" BinaryKey="BinaryId" DllEntry="MethodName" Execute="deferred"/>
如果想要检索整个 Blob,则可以使用以下代码:
string data = session["CustomActionData"];