使用 WiX (2.0) 安装多文件 NT 服务

发布于 2024-08-02 03:03:40 字数 3315 浏览 2 评论 0原文

如何在 WiX 中安装带有一些附加文件的服务,并定义哪个文件是实际的服务 EXE 文件?

场景:我有一个服务,它只是一个 EXE 文件,并使用以下代码将其作为 Windows NT 服务安装在 WiX 中:

<Component Id='InstallMyServiceComponent' Guid='{....}' DiskId='1'>
   <File Id='InstallMyServiceEXEFile' LongName='MyService.exe' 
         Name='MyServ.exe' src='MyService/bin/release/MyService.exe' KeyPath='yes'/>
   <ServiceInstall Id='InstallMyService' Name='MyService' Description='My Service'
         ErrorControl='normal' Start='auto' Type='ownProcess' Vital='yes' />
   <ServiceControl Id='UninstallMyService' Name='MyService' Remove='uninstall' 
         Wait='yes' />
</Component>
<Component Id='RunMyServiceComponent' Guid='.......'>
   <ServiceControl Id='RunMyService' Name='MyService' Start='install' 
         Stop='uninstall' Wait='no' />
</Component>

并且我有一个功能,允许安装并有选择地启动该服务。

现在,我的问题是 - 现在我的服务已经增长,单个 EXE 不再是单个 EXE - 它是多个文件、EXE、DLL 和一些支持文件。

但是,我现在该如何安装呢?

我尝试拥有一个包含所有文件的组件

<Component Id="MyService" Guid="......" DiskId="1">
  <File Id="fileMyService_framework_dll" LongName="Framework.dll" 
        Name="Framewrk.DLL" src="MyService\Framework.dll" />
  <File Id="fileMyService_dal_dll" LongName="MyServiceDAL.dll" 
        Name="SrvcDAL.DLL" src="MyService\ServiceDAL.dll" />
  <File Id="fileMyService_helpers_dll" LongName="Helpers.dll" 
        Name="Helpers.DLL" src="MyService\Helpers.dll" />
  <File Id="fileMyService_exe" LongName="MyService.exe" 
        Name="MySrv.EXE" src="MyService\MyService.exe" />
</Component>

首先,我尝试将 ServiceInstall 和 ServiceControl 标记添加到该组件:

<Component Id="MyService" Guid="......" DiskId="1">
  <File Id="fileMyService_framework_dll" LongName="Framework.dll" 
        Name="Framewrk.DLL" src="MyService\Framework.dll" />
  <File Id="fileMyService_dal_dll" LongName="MyServiceDAL.dll" 
        Name="SrvcDAL.DLL" src="MyService\ServiceDAL.dll" />
  <File Id="fileMyService_helpers_dll" LongName="Helpers.dll" 
        Name="Helpers.DLL" src="MyService\Helpers.dll" />
  <File Id="fileMyService_exe" LongName="MyService.exe" 
        Name="MySrv.EXE" src="MyService\MyService.exe" />
   <ServiceInstall Id='InstallMyService' Name='MyService' 
        Description='My Service' ErrorControl='normal' Start='auto' 
        Type='ownProcess' Vital='yes' />
   <ServiceControl Id='UninstallMyService' Name='MyService' 
        Remove='uninstall' Wait='yes' />
</Component>

但随后我的“Framework.dll”被设置为正在创建的服务的源路径...... ...

所以我想我应该使用 ServiceInstall 创建第二个组件来实际安装服务,并且我只是使用 FileRef 引用该服务 EXE 文件 - 但这似乎不存在(至少在 Wix2 中)。

<Component Id='InstallMyServiceComponent' Guid='{....}' DiskId='1'>
   <FileRef Id='fileMyService_exe' KeyPath='yes'/>
   <ServiceInstall Id='InstallMyService' Name='MyService' 
         Description='My Service' ErrorControl='normal' Start='auto' 
         Type='ownProcess' Vital='yes' />
   <ServiceControl Id='UninstallMyService' Name='MyService' 
         Remove='uninstall' Wait='yes' />
</Component>

那么 - 一个可怜的 WiX 作者需要做什么来安装所有必需的文件,并且仍然让 NT 服务安装来获取正确的 EXE 文件(而不仅仅是组件文件列表中的任意文件)?

马克

How do I install a service with some additional files in WiX, and define what file is the actual service EXE file?

Scenario: I had a service which was just a single EXE file, and installed it as a Windows NT service in WiX with this code:

<Component Id='InstallMyServiceComponent' Guid='{....}' DiskId='1'>
   <File Id='InstallMyServiceEXEFile' LongName='MyService.exe' 
         Name='MyServ.exe' src='MyService/bin/release/MyService.exe' KeyPath='yes'/>
   <ServiceInstall Id='InstallMyService' Name='MyService' Description='My Service'
         ErrorControl='normal' Start='auto' Type='ownProcess' Vital='yes' />
   <ServiceControl Id='UninstallMyService' Name='MyService' Remove='uninstall' 
         Wait='yes' />
</Component>
<Component Id='RunMyServiceComponent' Guid='.......'>
   <ServiceControl Id='RunMyService' Name='MyService' Start='install' 
         Stop='uninstall' Wait='no' />
</Component>

and I had a feature which would then allow to install and optionally start this service.

Now, my problem is - now my service has grown, and the single EXE is no longer a single EXE - it's multiple files, EXE, DLL, and a few support files.

However, how can I install that now??

I tried to have a component with all my files

<Component Id="MyService" Guid="......" DiskId="1">
  <File Id="fileMyService_framework_dll" LongName="Framework.dll" 
        Name="Framewrk.DLL" src="MyService\Framework.dll" />
  <File Id="fileMyService_dal_dll" LongName="MyServiceDAL.dll" 
        Name="SrvcDAL.DLL" src="MyService\ServiceDAL.dll" />
  <File Id="fileMyService_helpers_dll" LongName="Helpers.dll" 
        Name="Helpers.DLL" src="MyService\Helpers.dll" />
  <File Id="fileMyService_exe" LongName="MyService.exe" 
        Name="MySrv.EXE" src="MyService\MyService.exe" />
</Component>

First, I tried to just add the ServiceInstall and ServiceControl tags to this component:

<Component Id="MyService" Guid="......" DiskId="1">
  <File Id="fileMyService_framework_dll" LongName="Framework.dll" 
        Name="Framewrk.DLL" src="MyService\Framework.dll" />
  <File Id="fileMyService_dal_dll" LongName="MyServiceDAL.dll" 
        Name="SrvcDAL.DLL" src="MyService\ServiceDAL.dll" />
  <File Id="fileMyService_helpers_dll" LongName="Helpers.dll" 
        Name="Helpers.DLL" src="MyService\Helpers.dll" />
  <File Id="fileMyService_exe" LongName="MyService.exe" 
        Name="MySrv.EXE" src="MyService\MyService.exe" />
   <ServiceInstall Id='InstallMyService' Name='MyService' 
        Description='My Service' ErrorControl='normal' Start='auto' 
        Type='ownProcess' Vital='yes' />
   <ServiceControl Id='UninstallMyService' Name='MyService' 
        Remove='uninstall' Wait='yes' />
</Component>

but then my "Framework.dll" gets set as the source path for the service being created........

So I thought I'd create a second component to actually install the service, using ServiceInstall, and I'd just reference that service EXE file using FileRef - but that doesn't seem to exist (at least in Wix2).

<Component Id='InstallMyServiceComponent' Guid='{....}' DiskId='1'>
   <FileRef Id='fileMyService_exe' KeyPath='yes'/>
   <ServiceInstall Id='InstallMyService' Name='MyService' 
         Description='My Service' ErrorControl='normal' Start='auto' 
         Type='ownProcess' Vital='yes' />
   <ServiceControl Id='UninstallMyService' Name='MyService' 
         Remove='uninstall' Wait='yes' />
</Component>

So - what is a poor WiX author gotta do to install all the necessary files, and still get the NT Service installation to pick up the correct EXE file (not just any arbitrary file from the component's list of files) ??

Marc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不羁少年 2024-08-09 03:03:40

ServiceInstall 元素最终将指向ServiceInstall 所在组件的“KeyPath”。默认情况下,WiX 工具集会选择组件中的第一个File 或RegistryKey 元素作为KeyPath。 当您将文件添加到组件时,列表顶部的 .dll 就成为 KeyPath。

一般来说,较小的组件比较大的组件更好。 因此,更好的解决方案是将 DLL 放置在单独的组件中。 然后,您可以将 .exe 文件元素和 ServiceInstall 元素保留在同一组件中。 这使得一切都非常干净。

如果您希望将“服务”分组在一起,则可以创建一个 ComponentGroup 元素并将 ComponentRefs 放入 .exe 和 .dll 组件。 现在您有了一个可以从Feature/ComponentGroupRef 引用的东西。

The ServiceInstall element will end up pointing to the "KeyPath" of the Component the ServiceInstall is in. By default the WiX toolset picks the first File or RegistryKey element in your Component as the KeyPath. When you added files to your Component, the .dll at the top of the list became the KeyPath.

In general, smaller Components are better than bigger ones. So a better solution would be to place your DLLs in separate Components. Then you can leave the .exe File element and the ServiceInstall element in the same Component. That makes it all very clean.

If you then want the "service" grouped together, you can create a ComponentGroup element and put ComponentRefs to the .exe and .dll Components. Now you have a single thing you can reference from a Feature/ComponentGroupRef.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文