如何使用WiX将CustomActionData传递给CustomAction?

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


慕神8447489
浏览 813回答 3
3回答

白猪掌柜的

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

偶然的你

对于我们C ++ schlubs,您可以按如下方式检索Property:MsiGetProperty(hInstall, "CustomActionData", buf, &buflen);然后你解析'buf'。谢谢Bondbhai。
打开App,查看更多内容
随时随地看视频慕课网APP