views:

1041

answers:

1

I have 2 projects in my solution

  1. A Windows service

  2. Its Setup project

I need that my ProjectInstaller : System.Configuration.Install.Installer's method called OnAfterInstall to get the ProductName from the Setup Project. How do I do that?

+2  A: 

Within your setup project right click project and select View ->Custom Actions. Add a custom action. Now select Add Output ,now select your web service project and select ok.

Now select your custom action and set the CustomActionData property to contain something like /ProductName=[PRODUCTNAME] /whateveryouwant=[Whateveryouwant] (note that these are essentially name value pairs i.e. to access the productname the ProductName is the name and the value is PRODUCTNAME) etc. Note that the CustomActionData is the parameters which will be passed to your installer class. So the "PRODUCTNAME" will be the is the property name which is associated with the user interface dialog so in your case you prompt user for Product Name within yor installer so the label is Product Name and the corresponding property should be set as PRODUCTNAME (obviously you could change this the most important thing to note is that the UI property name must be the same as the property name in the CustomActionData ) for this example to work.

Now within your installer class you can get product name by doing

public override void Install(IDictionary stateSaver)
{
      // If you need to debug this installer class, uncomment the line below
      //System.Diagnostics.Debugger.Break();

       string productName = Context.Parameters["ProductName"].Trim();

       string whateveryouwant== Context.Parameters["whateveryouwant"].Trim();
}

note i included the commented code //System.Diagnostics.Debugger.Break(); which you can comment in so that you can debug the installer class.

hope this helps.

NBrowne
Excelent! Thank you!
Jader Dias
I have run into 2 problems: (1) It isn't working (2) When debugging it says: `Cannot evaluate expression because the code of the current method is optimized.`
Jader Dias
im not sure what the problem is without seeing your code or having more details.the error your getting is an error which happens for numerous regions. if you want you can send me a trimmed down version of your setup project and ill have a look to see if i can see whats wrong with it.
NBrowne
have you fixed this problem??? did my solution help you??
NBrowne