上面那篇之后其实还踩了个坑,安装Windows服务确实是打包进去了,但死活不能安装成功,从提示和日志看正好是Windows服务处理的地方出现了异常。以为是服务启动失败,但是服务在服务管理里手动启动是没问题的
而我的wxs当时是这么写的
<Componet Id="myservice"> <File Id="Service.exe" KeyPath="yes" Source="{Service.exe路径}"> <ServiceInstall Id="Installer" DisplayName="MyService" Name="MyService"/> <ServiceControl Id="Control" Name="MyServiceControl" Start="install" Stop="both" Remove="uninstall"/> </Componet>
查了半天没什么头绪,仔细一看报错才发现,出错的不是我的Service,而是ServiceControl。
起初没细想二者之间的关系,只从属性里看得出来ServiceControl是用来在安装/卸载过程中启动/停止Service的,而没去考虑二者是如何关联起来的,我以为只是在同一个Component标签下就会自动关联。
而实际上ServiceInstall和ServiceControl是通过Name进行关联的,即是说ServiceInstall和ServiceControl两个标签的Name属性需要保持一致,这样才能保证Service在流程中正确受到ServiceControl的控制。也就是说上面那段是Control的Name画蛇添足了,改成“MyService”与ServiceInstall保持一致就没问题了。