[英]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.