Ayo*_*o I 54 windows-installer custom-action wix wix3.5
如何通过延迟自定义操作检索CustomActionData上设置的属性?
Ayo*_*o I 127
延迟的自定义操作无法直接访问安装程序属性(引用).实际上,只有CustomActionData财产
session.CustomActionData
Run Code Online (Sandbox Code Playgroud)
以及此处列出的其他方法和属性在会话对象上可用.
因此,对于检索诸如之类的属性的延迟自定义操作INSTALLLOCATION,您必须使用类型51自定义操作(即设置属性自定义操作)来传递该信息,并且您将使用CustomAction的C#代码中的数据通过session.CustomActionData.(见参考和参考)
下面是51类自定义动作(CustomAction1)的示例,它将设置可以在其中检索的属性CustomAction2.
<CustomAction Id="CustomAction1"
Property="CustomAction2"
Value="SomeCustomActionDataKey=[INSTALLLOCATION]"
/>
Run Code Online (Sandbox Code Playgroud)
请注意,Property属性名称是CustomAction2.这个很重要.类型51操作的属性属性值必须与正在使用的自定义操作的名称相同/相同CustomActionData.(见参考)
注意名称SomeCustomActionDataKey的Value属性键/值对?在使用自定义操作(CustomAction2)中的C#代码中,您将CustomActionData使用以下表达式查找该属性:
string somedata = session.CustomActionData["SomeCustomActionDataKey"];
Run Code Online (Sandbox Code Playgroud)
用于从中检索值的键CustomActionData不是Property类型51自定义操作的属性值,而是属性中key=value对的键Value.(重要内容:CustomActionData通过设置与消费自定义操作的ID同名的安装程序属性来填充,但CustomActionData键不是安装程序属性.)(请参阅参考资料)
在我们的场景中,消费自定义操作是一个延迟的自定义操作,定义方式如下所示:
<Binary Id="SomeIdForYourBinary" SourceFile="SomePathToYourDll" />
<CustomAction Id="CustomAction2"
BinaryKey="SomeIdForYourBinary"
DllEntry="YourCustomActionMethodName"
Execute="deferred"
Return="check"
HideTarget="no"
/>
Run Code Online (Sandbox Code Playgroud)
配置InstallExecuteSequence
当然,消费自定义action(CustomAction2)必须在51自定义动作(CustomAction1)之后运行.所以你必须像这样安排他们:
<InstallExecuteSequence>
<!--Schedule the execution of the custom actions in the install sequence.-->
<Custom Action="CustomAction1" Before="CustomAction2" />
<Custom Action="CustomAction2" After="[SomeInstallerAction]" />
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)
对于我们C++ schlubs,您可以按如下方式检索Property:
MsiGetProperty(hInstall, "CustomActionData", buf, &buflen);
Run Code Online (Sandbox Code Playgroud)
然后你解析'buf'.谢谢Bondbhai.
如果传递给自定义操作的值不是密钥/对集...
IE
<SetProperty Id="CustomAction1" Before="CustomAction1" Value="data" Sequence="execute"/>
<CustomAction Id="CustomAction1" BinaryKey="BinaryId" DllEntry="MethodName" Execute="deferred"/>
Run Code Online (Sandbox Code Playgroud)
...然后可以使用以下方法检索整个 blob:
string data = session["CustomActionData"];
Run Code Online (Sandbox Code Playgroud)