如何使一个System.Configuration.Install.Installer来从安装项目的变量? [英] How to make a System.Configuration.Install.Installer to get a variable from the Setup project?

查看:1737
本文介绍了如何使一个System.Configuration.Install.Installer来从安装项目的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个项目在我的解决方案

I have 2 projects in my solution

  1. 一个Windows服务

  1. A Windows service

它的安装项目

我需要我的 ProjectInstaller:让System.Configuration.Install.Installer 的所谓OnAfterInstall方法产品名称从安装项目。我该怎么办呢?

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?

推荐答案

在安装项目右键单击项目并选择查看 - >自定义操作。添加自定义操作。现在选择添加输出,现在选择您的Web服务项目,并选择确定。

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.

现在选择您的自定义操作,并设置CustomActionData属性包含类似/产品名称[产品名称] / whateveryouwant = [Whateveryouwant](注意,这些基本上都是名值对IE访问将产品名称的产品名称是名称和=的值PRODUCTNAME)等注意CustomActionData是将被传递到您的安装程序类的参数。因此,PRODUCTNAME将是它与用户界面对话框相关联,以便在你的情况下,你的产品名称中的侑安装这样的标签是产品名称和相应的财产提示用户应设置为PRODUCTNAME(很明显的属性名你可以改变这一点需要注意的最重要的事情是,UI属性名必须是相同的CustomActionData属性名)在这个例子中工作。

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();
}

请注意我包括评论code //System.Diagnostics.Debugger.Break();你可以发表评论,以便您可以调试安装程序类。

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

希望这会有所帮助。

这篇关于如何使一个System.Configuration.Install.Installer来从安装项目的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆