How to pass CustomActionData to CustomAction using WiX?

How properties set on CustomActionData will be obtained by deferred user action?

+53
windows-installer wix custom-action
Jun 27 2018-12-12T00:
source share
3 answers

Pending user actions cannot directly access the properties of the installer ( link ). In fact, only the CustomActionData property

 session.CustomActionData 

and the other methods and properties listed here are available for the session object.

Therefore, for a deferred custom action to retrieve a property, such as INSTALLLOCATION , you must use a custom action of type 51, that is, the set-property custom action, to pass this information, and you will use the data from CustomAction C # code through session.CustomActionData . (see link and link )

The following is an example of a custom action of type 51 ( CustomAction1 ), in which the property that can be obtained in CustomAction2 will be set.

 <CustomAction Id="CustomAction1" Property="CustomAction2" Value="SomeCustomActionDataKey=[INSTALLLOCATION]" /> 

Notice the attribute name is Property CustomAction2 . It is important. The value of the attribute of the action property of type 51 must be equal to / identical to the name of the custom action that CustomActionData consumes. (see link )

Pay attention to the name SomeCustomActionDataKey in the key / value pairs of the Value attribute? In C # code, in a custom user action ( CustomAction2 ), you will see this property from CustomActionData using the following expression:

 string somedata = session.CustomActionData["SomeCustomActionDataKey"]; 

The key that you use to retrieve the value from CustomActionData is NOT the value of the Property attribute for a custom action of type 51, but the key from the key=value pair in the Value attribute. (Important takeaway: CustomActionData populated by setting the installer property with the same name as the user action ID, but CustomActionData are not settings for the installation.) (See link )

In our scenario, the user consumption action is a deferred user action, defined as below:

 <Binary Id="SomeIdForYourBinary" SourceFile="SomePathToYourDll" /> <CustomAction Id="CustomAction2" BinaryKey="SomeIdForYourBinary" DllEntry="YourCustomActionMethodName" Execute="deferred" Return="check" HideTarget="no" /> 

Configuring InstallExecuteSequence

Of course, the user action of the user ( CustomAction2 ) should be triggered after the user action of type 51 ( CustomAction1 ). Therefore, you will have to plan them as follows:

 <InstallExecuteSequence> <!--Schedule the execution of the custom actions in the install sequence.--> <Custom Action="CustomAction1" Before="CustomAction2" /> <Custom Action="CustomAction2" After="[SomeInstallerAction]" /> </InstallExecuteSequence> 
+127
Jun 27 2018-12-12T00:
source share

For us in C ++ schlubs, you return a Property as follows:

 MsiGetProperty(hInstall, "CustomActionData", buf, &buflen); 

Then you parse "buf". Thanks Bondbhai .

+8
Jul 25 '13 at 21:13
source share

If the value passed to the user action is not a key / pair set ...

those.

 <SetProperty Id="CustomAction1" Before="CustomAction1" Value="data" Sequence="execute"/> <CustomAction Id="CustomAction1" BinaryKey="BinaryId" DllEntry="MethodName" Execute="deferred"/> 

... then the entire blob can be obtained with:

 string data = session["CustomActionData"]; 
+4
Feb 18 '17 at 6:30
source share



All Articles