9

Когда я начинаю устанавливать с помощью InstallUtil это дает мне следующее сообщение об ошибке, я поставил ServiceInstaller и ServiceInstallerProcessслужбы Windows Проблема Установка

System.InvalidOperationException: Установка не удалась из-за отсутствия ServiceProcessInstaller. ServiceProcessInstaller должен быть либо содержащим установщик, либо он должен присутствовать в коллекции установщиков на том же установщике, что и ServiceInstaller.

Ожидание ваших ценных мыслей.

Благодарим Вас

ответ

1

Как правило, это означает, что вам не удалось приписать к установщику с RunInstaller (истина). Вот пример одного я иметь под рукой, что работает:

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); 
      } 
     } 
    } 
} 
20

У меня была та же проблема с установщиком и обнаружили, что в [YourInstallerClassName] .Designer.cs в InitializeComponent() метод, то 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}); 

и проект установки работает.

+0

+1, спасибо. Знаете ли вы какой-либо способ сделать то же самое через интерфейс? – FMFF

+1

@FMFF, для всех, кто заинтересован в этом с помощью пользовательского интерфейса, просто убедитесь, что оба сервиса и инсталлятор serviceProcessInstallers в вашем проекте Installer имеют родительский объект ProjectInstaller. – shadowf

+0

thanx, его проблема была решена. – yadavr

Смежные вопросы