0

I have properly overwrite commit in InstallerSetup.cs I do not wish to write the user entered value to app.config but rather I want to pass the string Context.Parameters["TESTPARAMETER"]; to another class in form1.cs on load function. I tried string test = InstallerSetup.Context.Parameters["TESTPARAMETER"]; but getting InstallerSetup.Context is null. Please Help.

InstallerSetup.cs

public static string SQLSERVERNAME = "";
public static string HMSTENANTDB;
public static string SQLLOGIN;
public static string SQLPASSWORD;

public override void Commit(IDictionary savedState)
{
    base.Commit(savedState);
    try
    { 
        SQLSERVERNAME = Context.Parameters["SQLSERVERNAME"];
        HMSTENANTDB = Context.Parameters["HMSTENANTDB"];
        SQLLOGIN = Context.Parameters["SQLLOGIN"];
        SQLPASSWORD = Context.Parameters["SQLPASSWORD"];  
    }
    catch (Exception e)
    {
         MessageBox.Show("Failed to update the application configuration file : " + e.Message);
         base.Rollback(savedState);
    }
}

from1.cs

InstallerSetup InsSetup = new InstallerSetup();
string Vsqlserver = InsSetup.Installers.Count.ToString();
string Vtenant = "";
if (InsSetup.Context != null)
{
    Vtenant = InsSetup.Context.Parameters["HMSTENANTDB"];
}
else
{
    Vtenant = "context is null";
}
PhilDW
  • 20,260
  • 1
  • 18
  • 28
Pax
  • 65
  • 1
  • 4
  • 19
  • It appears that you are using a visual studio setup project, so you need to confirm that you have added this as a custom action and show how passed those parameters to the custom action and explain where you got the values from. – PhilDW Jan 21 '18 at 19:45
  • On the User Interface parameter "HMSTENANTDB" is entered in a textbox. the "HMSTENANTDB" is recuperated in the custom action, Commit(). In form1.cs, "HMSTENANTDB" should be recuperated. I tried Vtenant = InsSetup.Context.Parameters["HMSTENANTDB"]; but Vtenant is null. – Pax Jan 22 '18 at 04:52
  • One of the things that makes this work is passing parameters in CustomActionData when the custom action is called, that's what I meant by "passed those parameters to the custom action", and this type of added info should be added as an edit to the question, but there is still insufficient data to address the issue. It's also still not obvious that you have actually added the custom action in the setup project, and I don't mean the code, I mean the call to it. – PhilDW Jan 22 '18 at 20:08
  • //passed those parameters to the custom action...................................... SQLSERVERNAME = Context.Parameters["SQLSERVERNAME"]; HMSTENANTDB = Context.Parameters["HMSTENANTDB"]; SQLLOGIN = Context.Parameters["SQLLOGIN"]; SQLPASSWORD = Context.Parameters["SQLPASSWORD"]; //................there is only these 4 lines in my custom actions – Pax Jan 23 '18 at 04:33

1 Answers1

0

As far as I can tell, the issue is that the property values are not being passed into the custom action. That would be the most obvious explanation. A commentfrom the poster says:

"passed those parameters to the custom action...................................... SQLSERVERNAME = Context.Parameters["SQLSERVERNAME"]; etc...

//................there is only these 4 lines in my custom actions"

which is essentially repeating the code that was previously posted.

This is NOT passing the values into the custom action. This is retrieving values which must already have been passed into the custom action.

Assuming that the custom action has been correctly added to (typically) the install nod of the custom action, and also assuming that the property names are in a TextBoxes dialog in the install, the values must be passed in to the custom action via the CustomActionData settings. To use one example, the CustomActionData setting must be something like:

/SQLSERVERNAME=[SQLSERVERNAME]

or /SQLSERVERNAME=[EDITA1] if EDIOTA1 is being used because that's the default property name.

However there is no reference to the TextBoxes (or any other) install dialog in the original question, so it's not really clear where the value of (say) SQLSERVERNAME is supposed to come from. It may be passed in on the msiexec command line, for example.

PhilDW
  • 20,260
  • 1
  • 18
  • 28