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.(见参考)

注意名称SomeCustomActionDataKeyValue属性键/值对?在使用自定义操作(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)

  • 如果你需要传递多个参数,你不能添加另一个CustomAction,它们会覆盖,但你应该设置你的参数用分号分隔它们:`Value ="ActionDataKey1 = Value1; ActionDataKey2 = Value2"`. (10认同)
  • 阿列克谢,谢谢花时间写这篇文章.这对我来说是一个非常大的帮助.不幸的是我只能给你+1 ... (5认同)

Pie*_*rre 8

对于我们C++ schlubs,您可以按如下方式检索Property:

MsiGetProperty(hInstall, "CustomActionData", buf, &buflen);
Run Code Online (Sandbox Code Playgroud)

然后你解析'buf'.谢谢Bondbhai.


Dav*_*sen 5

如果传递给自定义操作的值不是密钥/对集...

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)