WiX Installer初始化Windows服务时使用DLL而非EXE的问题排查
Windows服务SignalR Hub安装问题:WiX错误使用DLL而非EXE初始化服务
我开发了一个作为Windows服务运行的SignalR Hub,但遇到安装问题:WiX安装器始终用Project.dll而非Project.exe来初始化服务。
我通过CMD命令sc create TestServer binPath=分别测试了两种启动方式:用EXE可正常启动服务,用DLL则出现和安装程序相同的启动失败问题,因此可以确定是WiX安装配置有误。
以下是我的WiX安装代码:
<Component Id="SDCommunicationHub"> <File Id="SDCommunicationHub" Source="$(var.SDCommunicationHub.TargetPath)" /> <ServiceInstall Type="ownProcess" Name="SDCommunicationHub" DisplayName=" SDCommunicationHub" Description="Communication between PC and server" Start="auto" Account="[SERVICEACCOUNT]" Password="[SERVICEPASSWORD]" ErrorControl="normal" Vital="yes" /> <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="SDCommunicationHub" Wait="no" /> <ServiceConfig ServiceName="SDCommunicationHub" OnInstall="yes" DelayedAutoStart="yes" /> </Component>
问题原因与解决方法
问题核心是WiX项目引用的目标路径错误:
- 当前
$(var.SDCommunicationHub.TargetPath)指向的是SignalR Hub的类库项目(输出为DLL),而非承载服务的EXE宿主项目。Windows服务无法直接以DLL作为启动入口,必须指定可执行文件。
解决步骤:
- 确认WiX项目中引用的是Windows服务宿主EXE项目,而非SignalR Hub类库项目。
- 修改
File元素的Source属性,替换为EXE项目的TargetPath变量。例如,如果你的EXE项目名为SDCommunicationHubService,则改为$(var.SDCommunicationHubService.TargetPath)。 - 重新编译WiX安装包,安装后验证服务启动路径是否为EXE文件。
另外,ServiceInstall的Type="ownProcess"配置是正确的,这适用于独立进程的EXE服务,符合你的测试场景。
内容的提问来源于stack exchange,提问作者zohan3456
相关产品推荐
相关产品推荐

