Wix installer based TopShelf windows service fails to start

我怕爱的太早我们不能终老 提交于 2020-01-24 18:48:45

问题


I have written a bare-bones .NET 4.7.2 C# Windows Service using TopShelf and Quartz. The service works when I debug it using Visual Studio 2019 on my Windows 10 laptop. I then created a Wix 3.11.2 based setup to install and start this service. Now, I am trying to install the service on my laptop using this installer. The installer is able to copy the files but fails to start the service. Here is the code:

Product.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>

I get the following error when I run the Wix Installer:

If I try to start the service manually, I get the following error:

I have already tried the following:

  1. I am using the NT Authority\System account which should have the proper access.
  2. Currently my windows service isn't really doing anything. It's returing Task.CompletedTask. So, there shouldn't be a timeout scenario.
  3. I have tried with both debug and release builds.
  4. I am installing on the same machine I am developing on. So, .NET framework version shouldn't be an issue.
  5. I tried launching the debugger but it was unable to attach. So I didn't get any more details.
  6. I caught exceptions and wrote to the Event Log but that too doesn't have any more details.

回答1:


Installer Methods: I would inspect your service installer code inside the binary. There must be something that you are doing in the installation methods for the assembly / binary that is not replicated by MSI at installation time. What are you doing in these installer methods? Samples: 1 and 2.

WiX Service Installation: I would take out all attributes that are not needed in the WiX element. See this sample: Service Installation (Stropek). Particularly the Account attribute, just leave it out. Also take out that permissioning element for SYSTEM. Default permissions are better - they are already there.

Procmon.exe: You can inspect the system for what happens when you run InstallUtil.exe if you run Procmon.exe and inspect the information overload. Are you familiar with this tool? I would prefer not to go into it (again - rudimentary example), and I think it should be enough to study you installation method code instead.

Capture: It is also possible to use a setup-capture tool to scan the before and after state of the system when you run InstallUtil.exe. That requires a hefty tool (AdminStudio, Advanced Installer) and is rarely available for developers. Just for the record.


Links:

  • Cannot update a Windows Service installed by MSI
  • Wix installer upgrade with same "upgrade code" ID shows privilege error prompt
  • wix service install not enough permission

Additional:

  • Desktop applicaton not opening after installation in client system
  • Application is not getting opened after installing it with the installer created by "Visual studio installer"
  • Install a Windows service using a Windows command prompt?


来源:https://stackoverflow.com/questions/59076477/wix-installer-based-topshelf-windows-service-fails-to-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!