CustomActionDataに設定されたプロパティは、遅延カスタムアクションによってどのように取得されますか?
3 に答える
遅延カスタムアクションは、インストーラーのプロパティに直接アクセスできません(参照)。実際、CustomActionData
財産だけ
session.CustomActionData
ここにリストされている他のメソッドとプロパティは、セッションオブジェクトで使用できます。
したがって、などのプロパティを取得するための遅延カスタムアクションのINSTALLLOCATION
場合、タイプ51カスタムアクション(つまり、プロパティの設定カスタムアクション)を使用してその情報を渡す必要があり、CustomActionのC#コードからのデータを使用します。からsession.CustomActionData
。(リファレンスとリファレンスを参照)
CustomAction1
以下は、で取得できるプロパティを設定するタイプ51カスタムアクション()の例ですCustomAction2
。
<CustomAction Id="CustomAction1"
Property="CustomAction2"
Value="SomeCustomActionDataKey=[INSTALLLOCATION]"
/>
Property
属性名が。であることに注意してくださいCustomAction2
。これは重要。タイプ51アクションのProperty属性の値は、消費しているカスタムアクションの名前と等しい/同一である必要がありますCustomActionData
。(参照を参照)
属性キー/値ペアの名前SomeCustomActionDataKey
に注意してください。Value
消費するカスタムアクション()のC#コードで、次の式を使用しCustomAction2
てそのプロパティを検索します。CustomActionData
string somedata = session.CustomActionData["SomeCustomActionDataKey"];
値の取得に使用するキーは、タイプ51カスタムアクションの属性のCustomActionData
値ではなく、属性のペアのキーです。(重要なポイント:消費するカスタムアクションのIDと同じ名前のインストーラープロパティを設定することで入力されますが、キーはインストーラープロパティではありません。)(リファレンスを参照)Property
key=value
Value
CustomActionData
CustomActionData
このシナリオでは、消費するカスタムアクションは、以下のように定義された遅延カスタムアクションです。
<Binary Id="SomeIdForYourBinary" SourceFile="SomePathToYourDll" />
<CustomAction Id="CustomAction2"
BinaryKey="SomeIdForYourBinary"
DllEntry="YourCustomActionMethodName"
Execute="deferred"
Return="check"
HideTarget="no"
/>
InstallExecuteSequenceの構成
もちろん、消費するカスタムアクション(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>
私たちC++シュラブの場合、次のようにプロパティを取得します。
MsiGetProperty(hInstall, "CustomActionData", buf, &buflen);
次に、「buf」を解析します。ボンドバイに感謝します。
カスタムアクションに渡される値がキー/ペアセットではない場合...
すなわち
<SetProperty Id="CustomAction1" Before="CustomAction1" Value="data" Sequence="execute"/>
<CustomAction Id="CustomAction1" BinaryKey="BinaryId" DllEntry="MethodName" Execute="deferred"/>
...次に、次を使用してBLOB全体を取得できます。
string data = session["CustomActionData"];