[英]How to make a System.Configuration.Install.Installer to get a variable from the Setup project?
I have 2 projects in my solution 我的解决方案中有2个项目
A Windows service Windows服务
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.