Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change installer properties in C# custom action

How to change installer properties in my C# custom action?

like image 921
Bogdan Verbenets Avatar asked Apr 20 '11 10:04

Bogdan Verbenets


1 Answers

To access a WiX property, such as those set with the Property element, use the Session object's indexer. Here is an example:

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
string myProperty = session["MY_PROPERTY"];
return ActionResult.Success;
}

Setting properties is just as easy. You'll set the value by referencing the key with the name of your property. Here's an example:

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session["MY_PROPERTY"] = "abc";
return ActionResult.Success;
}

If the property doesn't exist when you set it, it will be created. Similarly, you can clear a property by setting its value to null. Creating or changing property values from a custom action doesn't stop the installer from displaying those properties in the install log. So, if a property holds information that ought to be hidden, you're better off declaring it in your WiX markup first and setting its Hidden attribute to yes.

<Property Id="MY_PROPERTY" Hidden="yes" />
like image 129
Bogdan Verbenets Avatar answered Oct 10 '22 23:10

Bogdan Verbenets