简体   繁体   English

如何使System.Configuration.Install.Installer从安装项目中获取变量?

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

I have 2 projects in my solution 我的解决方案中有2个项目

  1. A Windows service Windows服务

  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. 我需要我的ProjectInstaller : System.Configuration.Install.Installer的方法调用OnAfterInstall来从安装项目中获取ProductName How do I do that? 我怎么做?

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. 现在选择Add Output,选择您的Web服务项目,然后单击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; ie to access the product name, ProductName is the key and the value is PRODUCTNAME ). 现在选择自定义操作并将CustomActionData属性设置为包含类似/ProductName=[PRODUCTNAME] /whateveryouwant=[Whateveryouwant] (请注意,这些是键值对;即,要访问产品名称, ProductName是键和值是PRODUCTNAME )。

Note that CustomActionData contains the parameters that will be passed to your installer class. 请注意, CustomActionData包含将传递给安装程序类的参数。 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. PRODUCTNAME是与用户界面对话框中的输入控件关联的属性名称,因此在您的情况下,您将在yor安装程序中提示用户输入Product Name。 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. 所以标签是“产品名称”,相应的属性应该设置为PRODUCTNAME (显然你可以改变它,但最重要的是要注意的是UI属性名称必须与CustomActionData的属性名称相同)这个例子工作。

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(); 请注意我添加了注释代码//System.Diagnostics.Debugger.Break(); which you can comment in so that you can debug the installer class. 您可以在其中发表评论,以便您可以调试安装程序类。

hope this helps. 希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从System.Configuration.Install.Installer类显示WPF窗口 - displaying a WPF Window from a System.Configuration.Install.Installer class 从从System.Configuration.Install.Installer继承的类发出HTTP请求时,HttpRequest超时异常 - HttpRequest Timeout exception when making http request from a class inherited from System.Configuration.Install.Installer 如何在安装程序类中使用安装项目资源? - How to use setup project resource in installer class? 如何在InstallShield 2015中制作自定义安装程序 - How to make a custom installer in install shield 2015 如何使用 Visual Studio C# 和 MYSQL 创建安装程序或安装程序文件并添加 MYSQL 参考以将我的项目部署到另一个系统? - how to create a setup or installer file and adding MYSQL reference using visual studio C# and MYSQL for deploy my project into another system? 如何从安装项目获取安装路径 - How to get installation path from setup project Visual Studio安装程序安装项目从自定义操作执行回滚 - Visual studio installer setup project perform rollback from custom action 在VS 2010安装项目中自动安装.NET 4 Framework的配置 - Configuration to Automatically Install .NET 4 Framework in VS 2010 Setup Project 如何在安装程序中使用subinacl? C#安装项目 - How to Use subinacl in Installer ? C# Setup Project 如何将安装程序作为依赖项添加到C#应用程序的安装项目中? - How to add an installer as a dependency to a setup project for a C# app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM