[英]Wix installer based TopShelf windows service fails to start
我已经使用 TopShelf 和 Quartz 编写了一个基本的 .NET 4.7.2 C# Windows 服务。 当我在 Windows 10 笔记本电脑上使用 Visual Studio 2019 调试该服务时,该服务有效。 然后我创建了一个基于 Wix 3.11.2 的设置来安装和启动这个服务。 现在,我正在尝试使用此安装程序在我的笔记本电脑上安装该服务。 安装程序能够复制文件,但无法启动服务。 这是代码:
产品.wxs
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Broker Test" Language="1033" Version="1.0.0.0"
Manufacturer="Test"
UpgradeCode="{68813F65-1022-4E32-AC50-CD16B5927DAD}">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<Media Id="1" Cabinet="BrokerTest.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLDIR" Name="Application">
<Directory Id="WINDIR" Name="Service"/>
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="BrokerTest_MSI" Level="1">
<ComponentGroupRef Id="BrokerWindowsService" />
</Feature>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
<Property Id="INSTALLTYPE" Value="1"/>
</Product>
</Wix>
WinService.wxs
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Fragment>
<ComponentGroup Id="BrokerWindowsService">
<ComponentRef Id="Tb.WinService.Test" />
<ComponentRef Id="TopShelf"/>
<ComponentRef Id="Tb.ServiceConfig" />
<ComponentRef Id="Microsoft.Extensions.DependencyInjection" />
<ComponentRef Id="Microsoft.Extensions.DependencyInjection.Abstractions" />
<ComponentRef Id="Quartz" />
</ComponentGroup>
<DirectoryRef Id="WINDIR">
<Directory Id="DataDir" Name="Data"/>
<Component Id="Tb.WinService.Test" Guid="{F1DF09D9-98D8-4D63-9BB9-7581D56E1685}">
<CreateFolder Directory="DataDir">
<util:PermissionEx User="NT Authority\SYSTEM" GenericAll="yes"/>
</CreateFolder>
<File Id="Tb.WinService.Test.dll" Name="$(var.Tb.WinService.Test.TargetFileName)" Source="$(var.Tb.WinService.Test.TargetPath)" />
<File Id="Tb.WinService.Test.pdb" Name="$(var.Tb.WinService.Test.TargetName).pdb" Source="$(var.Tb.WinService.Test.TargetDir)$(var.Tb.WinService.Test.TargetName).pdb" />
<ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes"
Name="BrokerWindowsServiceTest"
DisplayName="Broker Windows Service Test"
Description="Runs scheduled tasks"
Start="auto" Account="NT Authority\SYSTEM"
ErrorControl="ignore"
Interactive="no" />
<ServiceControl Id="StartService"
Start="install" Stop="both" Remove="uninstall"
Name="BrokerWindowsServiceTest" Wait="yes" />
</Component>
<Component Id="TopShelf" Guid="{CEC3596B-4D38-4641-81EF-CBC09C4FE67E}">
<File Id="TopShelf.dll" Name="TopShelf.dll" Source="$(var.SolutionDir)packages\Topshelf.4.2.1\lib\net452\Topshelf.dll" Vital="yes" />
<File Id="TopShelf.xml" Name="TopShelf.xml" Source="$(var.SolutionDir)packages\Topshelf.4.2.1\lib\net452\Topshelf.xml" Vital="yes" />
</Component>
<Component Id="Tb.ServiceConfig" Guid="{A08D1440-4B2A-4DFB-9F55-27E81DC4B106}">
<File Id="Tb.Service.App.Config" Name="$(var.Tb.WinService.Test.TargetName).exe.config"
Vital="yes" KeyPath="yes" Source="$(var.Tb.WinService.Test.TargetDir)App.config" />
</Component>
<Component Id="Microsoft.Extensions.DependencyInjection" Guid="{8F69CFC4-02F9-479C-9C57-E2F88180E542}">
<File Id="Microsoft.Extensions.DependencyInjection.dll" Name="Microsoft.Extensions.DependencyInjection.dll"
Source="$(var.SolutionDir)packages\Microsoft.Extensions.DependencyInjection.3.0.1\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.dll" Vital="yes" />
</Component>
<Component Id="Microsoft.Extensions.DependencyInjection.Abstractions" Guid="{8EB47289-9527-4CE4-9991-EBF8997368DC}">
<File Id="Microsoft.Extensions.DependencyInjection.Abstractions.dll" Name="Microsoft.Extensions.DependencyInjection.Abstractions.dll"
Source="$(var.SolutionDir)packages\Microsoft.Extensions.DependencyInjection.Abstractions.3.0.1\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll" Vital="yes" />
</Component>
<Component Id="Quartz" Guid="{345DA6DA-F385-47A6-844C-3171ADE42E83}">
<File Id="Quartz.dll" Name="Quartz.dll" Source="$(var.SolutionDir)packages\Quartz.3.0.7\lib\net452\Quartz.dll" Vital="yes" />
<File Id="Quartz.xml" Name="Quartz.xml" Source="$(var.SolutionDir)packages\Quartz.3.0.7\lib\net452\Quartz.xml" Vital="yes" />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
运行 Wix 安装程序时出现以下错误:
如果我尝试手动启动该服务,则会收到以下错误:
我已经尝试了以下方法:
安装程序方法:我会检查二进制文件中的服务安装程序代码。 必须在安装时 MSI 未复制的程序集/二进制文件的安装方法中执行某些操作。 你在这些安装程序方法中做什么? 样品: 1和2 。
WiX 服务安装:我会去掉 WiX 元素中不需要的所有属性。 请参阅此示例: 服务安装(Stropek)。 特别是
Account attribute
,只需将其省略即可。 还要取出 SYSTEM 的许可元素。 默认权限更好 - 它们已经存在。
Procmon.exe :如果您运行Procmon.exe
并检查信息过载,您可以检查系统在运行InstallUtil.exe
时发生的情况。 你熟悉这个工具吗? 我不想深入研究它(再次 - 基本示例),我认为学习你的安装方法代码应该足够了。
捕获:当您运行InstallUtil.exe
时,也可以使用设置捕获工具来扫描系统的前后状态。 这需要一个强大的工具( AdminStudio
、 Advanced Installer
)并且很少可供开发人员使用。 只是为了记录。
链接:
附加:
确保 ServiceInstall Name 与 topshelf 服务的名称完全匹配
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.