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

时间:2020-04-27 18:56:34

标签: c# wix

任何人都可以帮助我找出为什么我的Windows服务无法启动的原因。

当我使用installutil安装它时,它可以完美工作。我决定使用wix为最终用户创建安装程序,但它不会启动。

这是我的代码

<?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>

安装程序抛出此错误:

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

我在命令行中运行了以下内容:

msiexec /i IWERPNextPoll_Setup /l*v log.txt

但是(我未经训练的眼睛)在日志文件中什么都没发现。

我编写的服务是我第一次涉足C#。我很高兴得到任何指导。

2 个答案:

答案 0 :(得分:1)

99.99%的时间这是服务问题。

一些专业提示。

1)在您确定一切稳定之前,请不要为前几个版本编写ServiceControl元素。安装后测试服务。

2)如果您确实编写了它,请让它坐在无法启动对话框中并开始分析。从命令提示符处运行EXE,然后查看它是否缺少依赖项或引发错误。服务中有很多日志代码,以了解问题所在。

ServiceInstaller是一种自注册反模式。也许您那里有一些代码在执行诸如创建EventSource或注册表项之类的代码,而没有它们,您的服务将引发异常。

只有分析/调试才能确定。

答案 1 :(得分:0)

@Christopher Painter的回答和对我问题的评论使我想到了这个问题。

问题是我没有在product.wsx中包括我的项目依赖项。我必须像这样添加...

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

此后,一切开始按预期运行