WiX - commit more than one Property to deferred Custom Action
Asked Answered
B

1

9

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.

Bildungsroman answered 28/10, 2013 at 7:9 Comment(0)
A
19

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.

Aposematic answered 28/10, 2013 at 7:54 Comment(6)
Thank´s, it make be sense and at the moment it looks like it does work. But at which sequence i had to call the immediate custom action in order that it is started after installing the files? Is there a way to implement that?Bildungsroman
Immediate action can't start after installing the files. That's why it is called immediate - it is executed immediately when the Windows Installer agent gets to it while processing. The immediate CA are designed to gather information from the system, the environment and the user, optionally validate it and pass to the deferred sequence for real execution. Immediate CA must never change the target system state.Aposematic
Than it´s up to the deferred action, that the file, it´s needed to install the templates, is not found.. hm..Bildungsroman
@YanSklyarenko how to send back the value to Wix from CustomAction <Property Id="RESTART" Secure="yes" Value="false" />Knighterrant
@asvignesh, I think this deserves a separate question as it's not covered by this one.Aposematic
@YanSklyarenko #45549086Knighterrant

© 2022 - 2024 — McMap. All rights reserved.