11

当我开始使用 installutil 安装时,它给了我以下错误,我设置了 ServiceInstaller 和 ServiceInstallerProcess,

System.InvalidOperationException:由于缺少 ServiceProcessInstaller,安装失败。ServiceProcessInstaller 必须是包含的安装程序,或者它必须存在于与 ServiceInstaller 相同的安装程序的 Installers 集合中。

关于如何解决问题的任何想法?

4

2 回答 2

25

我对安装程序有同样的问题,发现在 InitializeComponent() 方法的 [YourInstallerClassName].Designer.cs 中,dfault 生成的代码是缺少添加 ServiceProcessInstaller

        // 
        // [YourInstallerClassName]
        // 
        this.Installers.AddRange(new System.Configuration.Install.Installer[] {
        this.serviceInstaller1});

只需在我的情况下添加您的 ServiceProcessInstaller :

        // 
        // ProjectInstaller
        // 
        this.Installers.AddRange(new System.Configuration.Install.Installer[] {
        this.serviceProcessInstaller1,   //--> Missing
        this.serviceInstaller1});

并且安装项目有效。

于 2011-09-28T19:10:05.577 回答
1

通常,这意味着您未能将安装程序归因于 RunInstaller(true)。这是我方便使用的一个示例:

namespace OnpointConnect.WindowsService
{
    [RunInstaller(true)]
    public partial class OnpointConnectServiceInstaller : Installer
    {
        private ServiceProcessInstaller processInstaller;
        private ServiceInstaller serviceInstaller;

        public OnpointConnectServiceInstaller()
        {
            InitializeComponent();
        }

        public override string HelpText
        {
            get
            {
                return
                    "/name=[service name]\nThe name to give the OnpointConnect Service.  " +
                    "The default is OnpointConnect.  Note that each instance of the service should be installed from a unique directory with its own config file and database.";
            }
        }

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

        public override void Uninstall(IDictionary stateSaver)
        {
            Initialize();
            base.Uninstall(stateSaver);
        }

        private void Initialize()
        {
            processInstaller = new ServiceProcessInstaller();
            serviceInstaller = new ServiceInstaller();
            processInstaller.Account = ServiceAccount.LocalSystem;
            serviceInstaller.StartType = ServiceStartMode.Manual;

            string serviceName = "OnpointConnect";
            if (Context.Parameters["name"] != null)
            {
                serviceName = Context.Parameters["name"];
            }
            Context.LogMessage("The service name = " + serviceName);

            serviceInstaller.ServiceName = serviceName;

            try
            {
                //stash the service name in a file for later use in the service
                var writer = new StreamWriter("ServiceName.dat");
                try
                {
                    writer.WriteLine(serviceName);
                }
                finally
                {
                    writer.Close();
                }

                Installers.Add(serviceInstaller);
                Installers.Add(processInstaller);
            }
            catch (Exception err)
            {
                Context.LogMessage("An error occured while creating configuration information for the service.  The error is "
                                   + err.Message);
            }
        }
    }
}
于 2010-05-04T12:52:35.130 回答