简体   繁体   English

Wix 3.11 - 安装程序无法启动服务

[英]Wix 3.11 - Installer Can't Start Service

Can anybody help me find out why my Windows service won't start.谁能帮我找出为什么我的 Windows 服务无法启动。

When I install it with installutil , it works perfectly.当我使用installutil安装它时,它运行良好。 I decided to use wix to create an installer for the end user but it won't start.我决定使用wix为最终用户创建安装程序,但它不会启动。

Here's my code这是我的代码

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="IWErpnextPoll" Manufacturer="IWW" Language="1033" Version="1.0.0.0" UpgradeCode="ccc3c2fe-d20f-45ce-b978-4dc7c84ce6c8">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

        <Feature Id="ProductFeature" Title="IWERPNextPoll_Setup" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="IWErpnextPoll" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
            <Component Id="ProductComponent">
                <File Source="$(var.IWErpnextPoll.TargetPath)" />
                <ServiceInstall Id="ServiceInstaller" Name="IWErpnextPoll" Type="ownProcess" Vital="yes" DisplayName="ERPNext2Sage" Description="A background service." Start="auto" Account=".\LocalSystem" ErrorControl="normal" Interactive="no" />
                <ServiceControl Id="StartService" Name="IWErpnextPoll" Stop="both" Start="install" Remove="uninstall" Wait="yes" />
            </Component>
        </ComponentGroup>
    </Fragment>
</Wix>

The installer throws this error:安装程序抛出此错误:

Service 'IWErpnextPoll' (IWErpnextPoll) failed to start. Verify that you have sufficient privileges to start system services

I ran the following in the command line:我在命令行中运行了以下内容:

msiexec /i IWERPNextPoll_Setup /l*v log.txt

but (my untrained eyes) didn't find anything that seemed off in the very very log file.但是(我未经训练的眼睛)在非常非常的日志文件中没有发现任何看起来不对劲的东西。

The service I wrote is my first forray into C#.我编写的服务是我第一次尝试 C#。 I'll be very happy to get any pointers.我会很高兴得到任何指示。

99.99% of the time this is a problem with the service. 99.99% 的时间这是服务的问题。

A couple of pro tips.几个专业提示。

1) Don't author the ServiceControl element for the first few builds until you know the thing is solid. 1) 不要为最初的几个构建创建 ServiceControl 元素,直到你知道事情是可靠的。 Test the service after installation.安装后测试服务。

2) If you do author it, let it sit on the failed to start dialog and start profiling. 2)如果你确实创作它,让它坐在失败的启动对话框并开始分析。 Run the EXE from a command prompt and see if it is missing dependencies or throws errors.从命令提示符运行 EXE 并查看它是否缺少依赖项或引发错误。 Have lots of logging code in the service to understand what is wrong.在服务中有很多日志记录代码来了解问题所在。

ServiceInstaller is a form of self registration anti pattern. ServiceInstaller 是一种自注册反模式。 Perhaps you had some code in there doing something like creating an EventSource or a registry key and without it your service is throwing an exception.也许你有一些代码在那里做一些事情,比如创建一个 EventSource 或一个注册表项,如果没有它,你的服务就会抛出异常。

Only profiling/debugging will tell for sure.只有分析/调试才能确定。

The answer by @Christopher Painter and the comments on my question led me towards the problem. @Christopher Painter 的回答和对我问题的评论让我发现了这个问题。

The problem was that I did not include my project dependencies in product.wsx .问题是我没有在product.wsx中包含我的项目依赖项。 I had to add like so...我不得不像这样添加......

...
<Component Id="Serilog.dll">
    <File Source="$(var.IWErpnextPoll.TargetDir)Serilog.dll" />
</Component>
<Component Id="Serilog.Settings.AppSettings.dll">
    <File Source="$(var.IWErpnextPoll.TargetDir)Serilog.Settings.AppSettings.dll" />
</Component>
<Component Id="Serilog.Sinks.File.dll">
    <File Source="$(var.IWErpnextPoll.TargetDir)Serilog.Sinks.File.dll" />
</Component>
<Component Id="RestSharp.dll">
    <File Source="$(var.IWErpnextPoll.TargetDir)RestSharp.dll" />
</Component>
...

After this, things started working as expected在此之后,事情开始按预期工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM