无法更新由MSI安装的Windows服务 [英] Cannot update a Windows Service installed by MSI

查看:143
本文介绍了无法更新由MSI安装的Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个奇怪的问题,我找不到可行的解决方案.预先感谢您的帮助.

I'm facing a weird problem and I can't find a working solution. Thanks in advance for any help.

我用C#开发了Windows服务,该服务使用Newtonsoft.JSON库来解析一堆WebAPI的结果.该服务已与MSI一起部署,并且一切运行正常.

I developed a Windows Service in C# that use Newtonsoft.JSON library to parse the result from a bunch of WebAPI. The service is deployed with MSI and everything was working perfectly.

该服务的第一个版本使用的是Newtonsoft.JSON 6.0.8,但是最近我移到了11.0.2版.

The first version of the service was using Newtonsoft.JSON 6.0.8, but recently I moved to version 11.0.2.

我打包了一个新的MSI(具有正确的版本/产品ID/升级ID以确保升级),并且我正尝试通过执行以下操作的小型安装应用程序来部署新版本:

I packed a new MSI (with correct version/Product Id/Upgrade Id to ensure upgrading) and I'm trying to deploy the new version through a small install application that is performing the following:

  1. 使用System.ServiceProcess.ServiceController停止服务(如果已安装并正在运行)
  2. 使用System.ServiceProcess.ServiceController
  3. 卸载服务
  4. 运行在新的msi文件上调用msiexec的System.Process
  1. Stop the service (if installed and running) with a System.ServiceProcess.ServiceController
  2. Uninstall the service with a System.ServiceProcess.ServiceController
  3. Run a System.Process that invokes msiexec on the new msi file

结果:该服务无法正常工作,并且从日志中,我可以看到该应用程序仍在寻找Newtonsoft.JSON的6.0.8版本.

The result: the service is not working, and from the log, I can see that the application is still looking for the 6.0.8 version of Newtonsoft.JSON.

如果我尝试以下操作:

  1. 右键单击msi->卸载
  2. 右键单击msi->安装

一切正常,服务使用该库的11.0.2版...

Everything is working fine and the service uses the version 11.0.2 of the library...

我为此感到疯狂...如何修复/清理升级过程?

I'm going crazy about this... How can I fix/clean the upgrade process?

预先感谢

推荐答案

摘要 :修改并扩展您的MSI以处理所有与服务相关的任务:service installationservice deletionservice control.使用内置的MSI构造即可.

Summary: Modify and extend your MSI to handle all service related tasks: service installation, service deletion, service control. Use the built-in MSI constructs to do so.


服务安装 :不确定我是否遵循了整个问题方案的描述,但要解决的问题是,您应该让MSI自己在安装过程中控制服务安装和服务控制安装和升级过程.通过 ServiceInstall 在MSI文件中安装和控制服务 ServiceControl 表-如图所示,它们直接映射到WiX XML元素在这里:


Service Installation: Not sure I followed the whole problem scenario description, but the deal is that you should let the MSI itself control the service installation and service control during the installation and upgrade process. Services are installed and controlled in MSI files via the ServiceInstall and ServiceControl tables - that map directly to WiX XML Elements as illustrated here:

<Component>
   <File Source="$(var.SourceDir)\WindowsService.exe" />
   <ServiceInstall Name="MyService" ErrorControl="normal" Start="auto" Type="ownProcess" />
   <ServiceControl Id="MyService" Name="MyService" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
</Component>

让我链接到类似的文件如果以上内容不清楚,请在github 上进行采样(由 Rainer Stropek 提出).它更加完整和详尽.

Let me link to a similar sample on github (by Rainer Stropek) in case the above is not clear. It is more complete and elaborate.

链接 :此答案讨论了相同的问题:用于处理服务控制以及安装或卸载的自定义操作或自定义可执行文件被视为部署反模式中出现常见设计缺陷-这既不必要,也不理想也不可靠. MSI一次使用就具有全功能且可靠(除非您有非常特殊的服务,并且需要自定义操作出于某种原因" ).更正后,进行了新的更正:"出于某些原因很好的理由" ).

Links: This answer discusses the same issue: Service Installation & Control. Using custom actions or custom executables to deal with service control and installation or uninstallation is considered a deployment anti-pattern - it is neither necessary, desirable nor reliable. MSI is full-featured and reliable once used right (unless you have a very special and unusual service that needs custom actions "for some reason". Correction, new rectification follows: "for some very good reason").

这篇关于无法更新由MSI安装的Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆