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

百般思念 提交于 2019-12-12 07:18:18

问题


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?


回答1:


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

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

Note that CustomActionData contains the parameters that will be passed to your installer class. The PRODUCTNAME is the property name associated with the input control in the user interface dialog, and so in your case you would 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, but 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.



来源:https://stackoverflow.com/questions/2066048/how-to-make-a-system-configuration-install-installer-to-get-a-variable-from-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!