【问题标题】:The name 'Installers' does not exist in the current context当前上下文中不存在名称“安装程序”
【发布时间】:2012-07-05 15:16:15
【问题描述】:

我完全是开发 Windows 服务的菜鸟,我找到了有关实现标准 Windows 服务的教程。这是我找到的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;

namespace ReviewsSvc
{
[RunInstaller(true)]
public class ReviewsSvcInstaller
{
    private ServiceProcessInstaller processInstaller;
    private ServiceInstaller serviceInstaller;

    public ReviewsSvcInstaller()
    {
        processInstaller = new ServiceProcessInstaller();
        serviceInstaller = new ServiceInstaller();

        processInstaller.Account = ServiceAccount.LocalSystem;
        serviceInstaller.StartType = ServiceStartMode.Manual;
        serviceInstaller.ServiceName = "Reviews Updater";
        Installers.Add(serviceInstaller);
        Installers.Add(processInstaller);
    }
}
}

我已经添加了必要的参考资料,但我仍然收到关于“未找到安装程序”的错误消息。我错过了什么?

【问题讨论】:

  • 这个问题有什么地方太本地化了?

标签: c# windows-services installation


【解决方案1】:

你忘了指定基类

namespace ReviewsSvc 
{ 
    [RunInstaller(true)] 
    public class ReviewsSvcInstaller : Installer
    { 
        ....

【讨论】:

  • @MattDavey - 你的意思是什么?作者的整个问题是找不到类InstallerInstallers
  • @Ramhound 在这个例子中Installers 指的是System.Configuration.Install.Installer.Installers 属性——但正如史蒂夫指出的那样,他的类不是从System.Configuration.Install.Installer 派生的——因此是错误的。
  • 谢谢!还有一个问题:安装程序应该在不同的项目(不同的可执行文件)中还是与服务一起?如何使用安装程序?
  • 您可以从example in MSDN 以及您的代码中看到,ServiceInstaller 类需要知道主服务类的名称,并且该名称应该作为派生类的 ServiceName 找到来自项目中的 ServiceBase。安装服务(.NET 服务)的过程是通过实用程序 InstallUtil.exe。
  • @Steve - 那只咬了我一口。感谢您提醒我“子类安装程序”!非常感谢!
【解决方案2】:

确保主可执行文件 (EXE) 中的类 ReviewsSvcInstaller。安装程序在主入口程序集中查找此类。希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2015-08-30
    • 1970-01-01
    • 2019-05-06
    • 2013-10-02
    • 2014-04-22
    • 2017-06-17
    • 2015-09-11
    • 1970-01-01
    相关资源
    最近更新 更多