How to make System.Configuration.Install.Installer to get a variable from the installation project?

I have 2 projects in my solution

  • Windows service

  • Customization project

I need my ProjectInstaller : System.Configuration.Install.Installer method ProjectInstaller : System.Configuration.Install.Installer called OnAfterInstall to get the ProductName from the installation project. How to do it?

+7
c # visual-studio windows-installer setup-project
source share
1 answer

In the project project, right-click the project and choose View> User Actions. Add a custom action. Now select Add Output, select the web service project and click OK.

Now select your custom action and set the CustomActionData property to something like /ProductName=[PRODUCTNAME] /whateveryouwant=[Whateveryouwant] (note that these are key-value pairs, that is, to access the product name, ProductName is key, and the value is ProductName ).

Note that CustomActionData contains parameters that will be passed to your installer class. ProductName is the name of the property associated with the input control in the user interface dialog box, and so in your case you are asking the user for the product name inside the yor installer. Thus, the label is “Product Name” and the corresponding property should be set to ProductName (obviously, you can change this, but the most important thing to note is that the name of the user interface property must be the same as the name of the property in CustomActionData ), so this example worked.

Now in the installer class you can get the 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 commented code //System.Diagnostics.Debugger.Break(); which you can comment so you can debug the installer class.

hope this helps.

+8
source share

All Articles