Question

Is it possible for Installshield to run a WiX Custom Action which takes an additional parameter other than the required Session parameter? For example:

[CustomAction]
public static ActionResult CustomAction1(Session session, string param)
{
  session.Log(param);
  return ActionResult.Success;
}

(note the second parameter)

I am creating a Type 1 custom action through Installshield 2012. It takes a Function Name and I see no way to add parameter. I guess I'm hoping for a hack here, so if there is an unsupported mechanism through the MSI database, please share.

I was able to with Installshield Interop, and even being limited to string parameters, it allowed for a great solution of binary re-use of the across my installation projects, where the installation project was in control of specific parameters, rather than the custom action code itself.

Was it helpful?

Solution

I don't think it is possible to pass extra parameters to the custom action method. It is called by the Windows Installer, and it seems reasonable that it expects a well-defined signature.

However, you can work it around. If you need to pass some data to the custom action, you can use the Session object for this.

If your custom action is immediate, you can address the MSI properties in your custom action code like this:

session["PROPERTYNAME"] = "some value";

In immediate custom action the session object can address any property from the property table.

If you custom action is deferred, there's a mechanism to pass the necessary data into it. You should author a usual immediate "set-a-property" custom action and pass the necessary data to the property called like the name of your deferred CA. The sample is usually much more clear than shaping it into words:

<!-- This is a subsidiary CA, note the property name is equal to the deferred CA name -->
<CustomAction Id="SetForMyDeferredCA" Return="check" Property="MyDeferredCA" Value="source=[SourceFolder];target=[TargetFolder]"/>
<!-- And this is the deferred CA which does the job -->
<CustomAction Id="MyDeferredCA" Return="asyncWait" Execute="deferred" BinaryKey="CustomActions" DllEntry="MyMethodName" />

And inside the deferred CA you can address the passed data like this:

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

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top