VS2008 Windows服务在安装程序上删除再添加无法安装



如上图示,在安装程序上有多个Windows服务,将serviceInstaller2、serviceInstaller3删除后再添加,编译、安装,你会发现再也没办法成功安装这两个服务了,后来将前后的文件进行比较,发现问题主要在ProjectInstaller.Designer.cs上,下边列出了修改前后的代码,注意红色部分。

修改前:
private void InitializeComponent()
{
    this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
    this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
    this.serviceInstaller2 = new System.ServiceProcess.ServiceInstaller();
    this.serviceInstaller3 = new System.ServiceProcess.ServiceInstaller();
    //
    // serviceProcessInstaller1
    //
    this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
    this.serviceProcessInstaller1.Password = null;
    this.serviceProcessInstaller1.Username = null;
    //
    // serviceInstaller1
    //
    this.serviceInstaller1.ServiceName = "Service1";
    this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
    //
    // serviceInstaller2
    //
    this.serviceInstaller2.ServiceName = "Service2";
    this.serviceInstaller2.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
    //
    // serviceInstaller3
    //
    this.serviceInstaller3.ServiceName = "Service3";
    this.serviceInstaller3.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
    //
    // ProjectInstaller
    //
    this.Installers.AddRange(new System.Configuration.Install.Installer[] {
    this.serviceProcessInstaller1,
    this.serviceInstaller1,
    this.serviceInstaller2,
    this.serviceInstaller3
});

}

修改后:
private void InitializeComponent()
{
    this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
    this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
    this.serviceInstaller2 = new System.ServiceProcess.ServiceInstaller();
    this.serviceInstaller3 = new System.ServiceProcess.ServiceInstaller();
    //
    // serviceProcessInstaller1
    //
    this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
    this.serviceProcessInstaller1.Password = null;
    this.serviceProcessInstaller1.Username = null;
    //
    // serviceInstaller1
    //
    this.serviceInstaller1.ServiceName = "Service1";
    this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
    //
    // serviceInstaller2
    //
    this.serviceInstaller2.ServiceName = "Service2";
    this.serviceInstaller2.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
    //
    // serviceInstaller3
    //
    this.serviceInstaller3.ServiceName = "Service3";
    this.serviceInstaller3.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
    //
    // ProjectInstaller
    //
    this.Installers.AddRange(new System.Configuration.Install.Installer[] {
    this.serviceProcessInstaller1,
    this.serviceInstaller1});

}


评论: 0 | 引用: 0 | 查看次数: 5501
发表评论
登录后再发表评论!