Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass msiexec properties to a WiX C# custom action?

I have an MSI file being created with Wxs 3.0. My MSI references a C# custom action, written using the new C# Custom Action project.

I want to pass an argument to msiexec that gets routed to my custom action - for example:

msiexec /i MyApp.msi ENVIRONMENT=TEST#

In my .wxs file, I refer to my custom action like this:

<Property Id="ENVIRONMENT"/> <Binary Id="WixCustomAction.dll"  SourceFile="$(var.WixCustomAction.Path)" /> <CustomAction Id="WixCustomAction" BinaryKey="WixCustomAction.dll"    DllEntry="ConfigureSettings"/> <InstallExecuteSequence>    <Custom Action="WixCustomAction" After="InstallFiles"></Custom> </InstallExecuteSequence> 

My C# custom action is set up like this:

[CustomAction] public static ActionResult ConfigureSettings(Session session) {  } 

I was expecting to be able to access the property like this:

string environmentName = session.Property["ENVIRONMENT"];

but this doesn't seem to work.

How do I access the property I passed to msiexec in my custom action?

like image 892
David Laing Avatar asked May 07 '09 16:05

David Laing


People also ask

What is Targetdir WiX?

As I discovered at this link, TARGETDIR is actually supposed to represent the root of the drive with the most free space available (assuming there's more than one). That's why WiX projects have directories nested under there for Program Files, etc.


1 Answers

If instead of

<CustomAction Id="SetCustomActionDataValue"               Return="check"               Property="Itp.Configurator.WixCustomAction"               Value="[ENVIRONMENT],G2,[CONFIGFILE],[TARGETDIR]ITP_v$(var.VERSION_MAJOR)" /> 

you write this:

<CustomAction Id="SetCustomActionDataValue"               Return="check"               Property="Itp.Configurator.WixCustomAction"               Value="Environment=[ENVIRONMENT];G=G2;ConfigFile=[CONFIGFILE];TargetDir=[TARGETDIR]ITP_v$(var.VERSION_MAJOR)" /> 

then you will be able to reference your variables like this:

string env=session.CustomActionData["Environment"]; 
like image 173
Tomasz Grobelny Avatar answered Sep 23 '22 12:09

Tomasz Grobelny