Defkon1
Defkon1

Reputation: 522

Cannot update a Windows Service installed by MSI

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

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.

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

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

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.

If I try the following:

  1. Right-click on msi -> Uninstall
  2. Right-click on msi -> Install

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?

Thanks in advance

Upvotes: 2

Views: 1025

Answers (1)

Stein Åsmul
Stein Åsmul

Reputation: 42136

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.


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>

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.


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

Upvotes: 1

Related Questions