简体   繁体   English

调用Installer基本方法进行多个自定义操作?

[英]Call Installer base methods for multiple custom actions?

there is an existing visual studio setup project (MS VS Extension) that installs a Windows service via custom actions. 现有的Visual Studio安装项目(MS VS扩展)通过自定义操作安装Windows服务。

Now I am adding actions for populating the InstallLocation field (that is leaved empty by visual studio setup project created msi, see here: http://www.mikebevers.be/blog/2010/01/setup-project-product-installlocation-in-registry-is-empty/ ). 现在,我正在添加用于填充InstallLocation字段的操作(Visual Studio安装程序创建msi后将其留空,请参见此处: http : //www.mikebevers.be/blog/2010/01/setup-project-product-installlocation- in-registry-is-empty / )。

There are two alternatives to incorporate these actions for me: 有两种替代方法可以为我合并这些操作:

  1. Integrate the additional actions into the existing custom actions implementation that install the service 将其他操作集成到安装服务的现有自定义操作实现中
  2. Create separate class library for the additional actions and add them as second custom action items (this would allow re-using this class in all projects, without creating redundant code) 为其他操作创建单独的类库,并将它们添加为第二个自定义操作项(这将允许在所有项目中重用该类,而无需创建冗余代码)

For (1) there would be no problem. 对于(1)不会有问题。


Alternative (2) is what this question is about: 备选方案(2)是关于这个问题的:

Do I have to call the base.* methods in all custom actions? 我是否必须在所有自定义操作中调用base。*方法?

I don't get it from the MSDN documentation, if the base methods relate to the specific custom action only or if they relate to the global installer action, eg: https://msdn.microsoft.com/en-gb/library/system.configuration.install.installer.install(v=vs.110).aspx 如果基本方法仅与特定的自定义操作有关,或者与全局安装程序操作有关,则我无法从MSDN文档中获取它,例如: https : //msdn.microsoft.com/zh-cn/library/ system.configuration.install.installer.install(v = vs.110).aspx

If this was described too confusing: do I have to call System.Configuration.Install.Installer.Install() only once or for each custom action? 如果描述得太混乱了:我是否必须仅一次或针对每个自定义操作调用System.Configuration.Install.Installer.Install()

Thanks in advance! 提前致谢!

It took me some time to reach this point, but now I was able to try it - and it works with both custom actions calling the base methods (this means the below snippets are in both custom action implementations of Install() and Commit() : 我花了一些时间才能达到这一点,但是现在我可以尝试了-它可以与调用基本方法的两个自定义操作一起使用(这意味着下面的摘录在Install()Commit()自定义操作实现中:

public override void Install(IDictionary stateSaver)
{
    base.Install(stateSaver);

    // custom stuff ...
}

public override void Commit(IDictionary savedState)
{
    base.Commit(savedState);

    // custom stuff ...
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM