views:

47

answers:

2

I wrote a Windows Service using C#.NET. To install the service, I've added a "Project Installer" class that inherited from the Installer class and decorated with the [RunInstaller].

Without the [RunInstaller] decoration, I cannot install the service using installutil.

Why is it that by deploying the service using the ServiceInstall table in MSI, MSI was able to install the service without a [RunInstaller] decoration?

PS: I used WiX to author the MSI:

<ServiceInstall Id="RegistryReaderInstall" DisplayName="Registry Reader Service" Name="Registry Reader" ErrorControl="critical" Start="auto" Type="ownProcess"/>
A: 

Basically WiX is not calling the ProjectInstaller; it's simply using MSI tables.

If you really need to call the ProjectInstaller (because it sets up other stuff) then you need to use a WiX custom action. Note this is not considered the best option (WiX-users).

Sean Fausett
+1  A: 

I wrote a blog article about this 4 years ago:

MSI vs .NET

Basically the expert level answer is that Installer class custom actions are an evil antipattern invented by the .NET community. They are an extension of the RegSvr32 pattern and doesn't fit with the MSI table driven declarative design and shouldn't be used.

The Service Control Manager is an unmanaged API ( Advapi32.dll ) that pre-dates the .NET framework. Windows Installer already had excellent support in the 1990's for the SCM before .NET came along. Then .NET came along to create a pattern for writing managed services and while the ability to inherit from ServiceBase to get most of the plumbing for free is a good thing, the use of InstalUtil is not.

BTW you should also drop to DOS and check out the SC command. This will allow you to do all sorts of service installation actions in case you need to do something in the development environment without running an MSI.

Christopher Painter