2010-05-04 18 views
9

Quando inizio di installare usando installutil mi dà seguente errore, ho impostato ServiceInstaller e ServiceInstallerProcessWindows Service Problema di installazione

System.InvalidOperationException: Installazione non riuscita a causa della mancanza di un ServiceProcessInstaller. ServiceProcessInstaller deve essere il programma di installazione contenente oppure deve essere presente nella raccolta Installer sullo stesso programma di installazione di ServiceInstaller.

In attesa di preziosi pensieri.

Ringraziandovi

risposta

1

Di solito, questo significa che non siete riusciti ad attribuire l'installatore con RunInstaller (vero). Ecco un esempio di quello che ho a portata di mano che funziona:

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

Ho avuto lo stesso problema con il programma di installazione e ha scoperto che nelle [YourInstallerClassName] .Designer.cs a InitializeComponent() metodo, il dfault codice generato è mancante aggiungere il ServiceProcessInstaller

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

Basta aggiungere il tuo ServiceProcessInstaller nel mio caso la sua:

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

e il progetto di installazione funziona.

+0

+1, grazie. Conosci un modo per fare la stessa cosa tramite l'interfaccia utente? – FMFF

+1

@FMFF, per chiunque sia interessato a farlo attraverso l'interfaccia utente, è sufficiente assicurarsi che sia ServiceInstaller sia serviceProcessInstallers sul progetto Installer abbiano il genitore come ProjectInstaller. – shadowf

+0

grazie, ha risolto il mio problema di installazione. – yadavr