2013-10-16 83 views
0

我是WiX的新手,并且正在尝试创建一个安装包含3个Windows服务的应用程序的安装程序。其中一个服务在虚拟中提供了一个用于调试其他两个服务的钩子。我可以使用InstallUtil成功安装服务,但需要包含其他组件和应用程序的更完整的安装。使用WiX来安装具有多个Windows服务的进程

在WXS文件中,组件中有三个ServiceInstall节点和三个ServiceControl节点。这些节点引用应用程序可执行文件中定义的三个服务的名称。

运行安装程序成功完成,报告的服务已安装并启动。但是,第二个和第三个服务的功能不可用,并且检查事件日志会显示输入3次虚拟服务的启动消息。类似的,当停止所有3个服务 - 虚拟关机消息出现3次。看起来WSX文件中的服务声明实际上安装了服务之间存在一些故障。

从与该组件的WSX文件的XML如下:

<Component Id="LPMMANAGEMENTSERVICE.EXE" 
    Guid="36C773C5-EF30-4D8D-B9CC-015EBE906CCB" DiskId="1"> 
     <File Id="LPMMANAGEMENTSERVICE.EXE" Name="LPMManagementService.exe" Source="Projects\LumePress\LumeJetManagement\LPMManagementService\bin\Release\LPMManagementService.exe" /> 
      <ServiceInstall Name="LPMManagementDebug" Type="ownProcess" Start="auto" 
          ErrorControl="critical" Interactive="no" Account="LocalSystem" 
          Vital="yes" DisplayName="LPM Management Service Debugger" 
          Description="This service provides a process startup without starting the key services, allowing a debugger to attached and handle onstart and onstop" 
          Id="LPM_Management_Service_Debugger_Installer" /> 
      <ServiceInstall Name="LPMServiceListeners" Type="ownProcess" Start="auto" 
          ErrorControl="critical" Account="LocalSystem" DisplayName="LPM Management Service Listeners" 
          Id="LPM_MANAGEMENT_SERVICE_LISTENERS_INSTALL" Interactive="no" Vital="yes" 
          Description="Provides WebAPI and WCF Services for the LPM Architecture" /> 
      <ServiceInstall Name="LPMMonitoring" Type="ownProcess" Start="auto" ErrorControl="critical" 
          Description="Manages and logs events from the LPM Core perl executable" 
          DisplayName="LPM Management Service LPM Core and Monitoring" Account="LocalSystem" 
          Id="LPM_MANAGEMENT_SERVICE_CORE_INSTALL" Interactive="no" Vital="yes"> 
       <ServiceDependency Id="LPMServiceListeners" /> 
      </ServiceInstall> 
      <ServiceControl Id="LPM_MANAGEMENT_DEBUG_CONTROL" Name="LPMManagementDebug" 
          Remove="uninstall" Start="install" Stop="both" /> 
      <ServiceControl Id="LPM_MANAGEMENT_SERVICE_LISTENERS_CONTROL" Name="LPMServiceListeners" 
          Remove="uninstall" Start="install" Stop="both" /> 
      <ServiceControl Id="LPM_MANAGEMENT_SERVICE_CORE_CONTROL" Name="LPMMonitoring" 
          Remove="uninstall" Start="install" Stop="both" /> 
     </Component> 

我发现,涉及到创建多个服务的各种问题,但我找不到任何问题,直接关系到这个场景或类似的足以推断我做错了什么。

希望有人会有一个可能有所帮助的建议。

如果我错过了某些明显的东西,很乐意提供更多信息。

+0

我想你应该有一个组件和每个ServiceControl的文件,但你有三个同一个文件的ServiceControl。您是否尝试为每个服务创建一个组件和文件,并为这些组件中的每一个分配一个ServiceControl? –

+0

您是否找到解决方案@ChandyHendrix? – Farinha

回答

0

解决方案:将参数传递给可执行文件,并根据此参数确定要实例化的服务。 通过ServiceInstall标签参数传递到您的WindowsService可执行如下:

<ServiceInstall Name="LPMManagementDebug" Type="ownProcess" Start="auto" 
    ErrorControl="critical" Interactive="no" Account="LocalSystem" 
    Vital="yes" DisplayName="LPM Management Service Debugger" 
    Description="This service provides a process startup without starting the key services, allowing a debugger to attached and handle onstart and onstop" 
    Id="LPM_Management_Service_Debugger_Installer" 
    Arguments = "MyService1" /> 
<ServiceInstall Name="LPMServiceListeners" Type="ownProcess" Start="auto" 
    ErrorControl="critical" Account="LocalSystem" DisplayName="LPM Management Service Listeners" 
    Id="LPM_MANAGEMENT_SERVICE_LISTENERS_INSTALL" Interactive="no" Vital="yes" 
    Description="Provides WebAPI and WCF Services for the LPM Architecture" 
    Arguments = "MyService2" /> 

更新的Program.cs您的Windows服务项目如下:

static void Main(string[] args) 
{ 
    ServiceBase[] ServicesToRun; 

    if (args != null && args.Length > 0) 
    { 
     switch (args[0]) 
     { 
      case "MyService2": 
       ServicesToRun = new ServiceBase[] 
       { 
        new MyService2() 
       }; 
       break; 
      case "MyService1": 
      default: 
       ServicesToRun = new ServiceBase[] 
        { 
         new MyService1(), 
        }; 
       break; 
     } 
    } 
    ServiceBase.Run(ServicesToRun); 
} 
+0

这真的是解决方案吗?看起来有点迟缓的.Net有一种方法来Run()一个ServiceBase的数组,然后当需要运行多个时需要破解它。 此外,我发现使用'installutil'安装Windows服务成功安装了2个服务,触发了2个“服务启动”事件,并且从那里一切正常运行。使用WiX是一件很糟糕的事情。 – Farinha

0

当您要安装一个可执行多种服务,你需要将类型设置为“sharedProcess”,否则只有一个服务将启动,其他服务将不会启动。