Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WiX - commit more than one Property to deferred Custom Action

I have a problem with my WiX installer in contact with deferred / immediate custom actions. Please excuse my english.

I want to surrender some properties, entered by the user, to a deferred custom action. I know that I need a immediate custom action and "CustomActionData" to do that. I´ve implement it at this way.

The binary:

<Binary Id='myAction'  SourceFile='.\TemplateGeneration.CA.dll'/>

The immediate custom action:

<CustomAction Id='Datenuebergabe' Property='DoSomething' Value='InstalllocVar=[INSTALLLOCATION]'/>

The deferred custom action:

<CustomAction Id='TemplateGenerationInstallKey' BinaryKey ='myAction' DllEntry='DoSomething' Impersonate='no' Execute='deferred'  Return='check' HideTarget='yes'/>

The InstallExecuteSequence

 <InstallExecuteSequence>

  <Custom Action="Datenuebergabe" Sequence="1399"/>
  <Custom Action="TemplateGenerationInstallKey" Before="InstallFinalize"/>

 </InstallExecuteSequence>

Calling the property in the deferred custom action:

string somedata = session.CustomActionData["InstalllocVar"];
TemplateEngineCall(somedata+"templates", "install_key_cmd", somedata+"scripts", "install_key.cmd");

My problems: If I try to install my program it breaks. With this code i only can surrender one property, but I need to commit more than one.

For information: When I have a look at the log file, there´s a System.Collections.Generic.KeyNotFoundException while the custom action call.

Why doesn´t this work? Well, I need the deferred custom action to write into the "program files folder". Because of the needed rights, the deferred custom action is required and the immediate custom action executed before the deferred should help to handle the properties. Is it possible to do that?

I hope you understand what are my problems and possible you can try to help me.

like image 564
Schneckschjen Avatar asked Oct 28 '13 07:10

Schneckschjen


1 Answers

First of all, there's a mistake in the way you pass the data from immediate custom action to the deferred one. The name of the Property you use in the immediate custom action must be exactly the same as the Id of the deferred custom action. In your case:

<!-- immediate CA -->
<CustomAction Id='Datenuebergabe' Property='DoSomething' Value='InstalllocVar=[INSTALLLOCATION]'/>

<!-- deferred CA -->
<CustomAction Id='DoSomething' BinaryKey ='myAction' DllEntry='DoSomething' Impersonate='no' Execute='deferred'  Return='check' HideTarget='yes'/>

This will resolve the problem with KeyNotFound exception.

Now, back to your question how to pass more than 1 value.

First, in the immediate CA use ; separator to pass the name-value collection, like this:

<CustomAction Id="SetForDoSomething" Return="check" Property="DoSomething" Value="source=[ArchiveFolder][ARCHIVENAME];target=[WebsiteFolder]"/>

As you can see, there are 2 name-value pairs we pass to the deferred CA here, source and target. In the deferred CA, use the following code to take those values out:

var source = session.CustomActionData["source"];
var target = session.CustomActionData["target"];

And that's it.

like image 142
Yan Sklyarenko Avatar answered Nov 08 '22 23:11

Yan Sklyarenko