我正在使用WiX为基于NServiceBus的解决方案创建安装程序,但是在安装后我无法启动主机服务。
如果我使用NServiceBus.Host.exe /install
从命令行运行主机的安装程序,它会安装正常,甚至在我启动服务时成功启动。
但是,当我使用ServiceInstall
元素在WiX中创建服务时,它无法启动该服务。我尝试使用ServiceControl
元素在我的安装程序中启动服务,以及从WIndows服务控制面板进行安装后。
我试图在WiX中使用的代码是:
<Component Id="NServiceBus.Host" Guid="PUT-GUID-HERE" Win64="yes">
<File Id="NServiceBus.Host" KeyPath="yes"
Source="$(var.[Project].TargetDir)NServiceBus.Host.exe" Checksum="yes" />
<ServiceInstall Id="NServiceBus.Host.Install"
Name="[Product].Host" DisplayName="[Product]" Type="ownProcess"
Account="NT Authority\Network Service" Interactive="no" Start="auto"
Vital="yes" ErrorControl="normal">
<ServiceDependency Id="MSMQ" />
<ServiceDependency Id="MSDTC" />
</ServiceInstall>
<ServiceControl Id="NServiceBus.Host.Control" Name="[Product].Host"
Start="install" Stop="both" Remove="uninstall" Wait="yes" />
</Component>
我在其他项目中使用了相同的代码来安装和运行服务,所以我很确定这个问题与NServiceBus的主机有关。此处的服务似乎也可以正确安装,但无法运行。
是否有人能够使用WiX安装NServiceBus.Host.exe
作为服务?或者有人知道当我运行NServiceBus.Host.exe /install
我应该在我的WiX安装程序中复制时是否还有其他步骤?
我知道我可以在运行CustomAction
的WiX中创建NServiceBus.Host.exe /install
,但我宁愿避免这种情况,并以正确的(WiX)方式安装服务。它还避免了我需要考虑卸载操作和排序。
编辑:作为参考,这是我使用WiX MsmqExtension
创建队列的方式:
<Component Id="NServiceBus.Host.Queue" Guid="PUT-GUID-HERE" Win64="yes">
<msmq:MessageQueue Id="Queue1" Label="[Product] Host"
PathName=".\private$\[Product].Host"
Transactional="yes" PrivLevel="optional" />
<msmq:MessageQueue Id="Queue2" Label="[Product] Host Retries"
PathName=".\private$\[Product].Host.Retries"
Transactional="yes" PrivLevel="optional" />
<msmq:MessageQueue Id="Queue3" Label="[Product] Host Timeouts"
PathName=".\private$\[Product].Host.Timeouts"
Transactional="yes" PrivLevel="optional" />
<msmq:MessageQueue Id="Queue4" Label="[Product] Host Timeouts Dispatcher"
PathName=".\private$\[Product].Host.TimeoutsDispatcher"
Transactional="yes" PrivLevel="optional" />
</Component>
答案 0 :(得分:1)
您不应尝试在WiX中复制NServiceBus主机安装程序。有很多事情会发生,每次发布时都会发生变化,所以你会尝试的任何东西都会非常脆弱。
您应该只使用正确的命令行处理程序执行主机,而不是ServiceInstall元素,让NServiceBus自行处理。我对WiX并不熟悉,但我认为有一些方法可以使用命令行参数执行任意可执行文件吗?
要清楚
是的,将NServiceBus端点安装为具有WiX的服务是可能的。我说你不应该,不是你不能。
如果您不使用NServiceBus安装程序来安装端点,那么您将错过队列生成和NServiceBus主机调用WiX的其他任务(不知道NServiceBus如何操作)不能。
答案 1 :(得分:1)
你快到了。您需要将NServiceBus.Host.exe
期望的命令行参数传递到Arguments
标记上的ServiceInstall
属性,如
<ServiceInstall Id="NServiceBus.Host.Install"
Name="[Product].Host" DisplayName="[Product]" Type="ownProcess"
Account="NT Authority\Network Service" Interactive="no" Start="auto"
Vital="yes" ErrorControl="normal"
Arguments="-service NServiceBus.Production /serviceName:[Product].Host">
首先使用NSB主机安装您的服务,然后查看Windows服务和安装中的所有命令行参数。将它们放入您的WiX安装程序。
编辑:
如果您不想运行自定义操作以使NSB在WiX @安装时创建队列和/或执行其他操作,则可以通过在代码中添加自定义NSB profile来实现类似的效果,例如< / p>
namespace YourNamespace
{
public class YourProfile : NServiceBus.IProfile { }
public class YourProfileBehaviour : IHandleProfile<YourProfile>
{
public void ProfileActivated()
{
WindowsInstallerRunner.RunInstallers = true;
}
}
}
请记住,使用上面的配置文件将在每次重新启动服务时运行NSB安装程序代码(例如,必要时检查并添加队列)。我想两种方式都有权衡。