Archive

Posts Tagged ‘custom action’

Passing parameters collected in dialog to Custom Action in msi C#

May 14th, 2011 Comments off

I was a little lost to why the dialog boxes I was adding to my windows installer msi was not being passed to my custom action.

There is a very simple item that I overlooked, and that is you must specify what values you want sent to your custom action.

On the properties of the custom action, there is a property called CustomActionData.

The format of this properties is:

/ParamName1=”[DIALOGPROPERTY1]” /ParamName2=”[DIALOGPROPERTY2]” …. etc

Custom Action Properties

Custom Action Properties

Then to use the parameters you will use the following code:

string sqlServer = Context.Parameters["ParamName1"];
string username = Context.Parameters["ParamName2"];
string password = Context.Parameters["ParamName3"];

C# Update app.config in msi custom action

May 12th, 2011 3 comments

I have been doing quite a lot of googling about updating the app.config file during an installation using an msi custom action. I found this blog by Rob Aquila, however this did not really work for me.

I then came across this question on StackOverflow that almost solved the problem. The key to the solution was to open the app.config and save directly to this file.

The issue I found with the later solution is that for some reason I could not get the Context.Parameters = “targetdir”. When the install was running this was always returning null.

So my solution that worked for me is as follows:

public override void Install(System.Collections.IDictionary savedState)
{
    base.Install(savedState);

    var targetAssembly = Context.Parameters["assemblypath"];

    var path = string.Format("{0}.config", targetAssembly);

    var xmlDoc = new System.Xml.XmlDocument();

    xmlDoc.Load(path);

    var node = xmlDoc.SelectSingleNode("/configuration/userSettings/Application.Properties.Settings/setting[@name='SettingName']/value");
    node.InnerText = "PLACE NEW PARAMATER HERE";

    xDoc.Save(path);
}

Thank you to Khalil Dahab for his response on StackOverflow

%d bloggers like this: