Erix
Erix

Reputation: 7105

Can I somehow get values entered in the User Interface into my custom actions installer class code?

This seems like it should be pretty simple. I have a Windows installer project. Inside the UI, I added a dialog with 2 radio buttons. The installer has a custom action on 'Install' which uses an install class from the primary output of one of my projects. Is it possible to get the value of the selected radio button from within the Install method in the installer class?

Upvotes: 2

Views: 2431

Answers (3)

PhilDW
PhilDW

Reputation: 20780

If this is a Visual Studio installer project, and it seems to be, the properties window of the added RadioButtons dialog tells you that the property name is BUTTON2 so that's what you pass into your custom action installer class with the standard /mybutton=[BUTTON2] type of syntax so you get the value using the key mybutton from Context.Parameters collection in the installer class.

The dialog behavior is described here:

https://msdn.microsoft.com/en-us/library/vstudio/9x23561f(v=vs.100).aspx

and you'd end up with a value of 1 or 2 in your code, depending on which was selected. With installer classes Visual Studio provides that infrastructure around the call, including CustomActionData handling

Like this:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/279e0aea-077c-4150-89ae-55d8494def1b/installer-class-passing-parameters

http://blog.billsdon.com/2011/05/passing-parameters-collected-dialog-custom-action-msi-c/

Upvotes: 1

Colin Young
Colin Young

Reputation: 3058

If you use WiX Deployment Tools Foundation (DTF) to develop your custom action, you are able to access the properties:

  • for immediate execution via session[property name] (admittedly, I'm not too familiar with this method, so you might need to experiment a bit) See this stackoverflow question for more details
  • for deferred execution via CustomActionData
    • you can populate CustomActionData with the values of your properties elsewhere in your installer and read as session.CustomActionData[property name]

One trick with the CustomActionData is your property name must match the name of your custom action and you provide the values as a semicolon-delimited list of name=value pairs, e.g. Name1=value1;Name2=value2 etc.

You will also need to run your assembly through MakeSfxCA.exe to make your action available to the installer. You can do that as a post-build event in Visual Studio.

DTF-based .Net custom actions can be used in WiX or InstallShield installers (likely any tool that produces MSI installers).

Upvotes: 0

Bogdan Mitrache
Bogdan Mitrache

Reputation: 11013

To get/set a property you need an MSI handle which, from what I know, you cannot obtain from a .NET Installer class custom action.

What you could do is to configure the custom action to accept new parameters, and assign the value of your property to those parameters, when configuring the custom action.

Upvotes: 2

Related Questions