Deploying Services in C#

In case any of you have ever written a Windows Service in C#, I am quite sure you have deployed the service via a setup and deployment project in Visual Studio .NET. In any case writing and deploying such a service is quite an easy task. You can find instructions on how to write a service and get it installed via a setup file on MSDN.

Now this works fine for the ideal case where you perform only two actions on your service, namely Install and Uninstall. However if you have worked on Windows and installed as many programs as I have, you might have noticed that under Add / Remove programs almost all apps have an option – Repair. Now a repair merely reinstalls the application. In case of the above mentioned setup project, the re-installation fails with the error

“The specified service already exists”

This occurs because a reinstall includes running custom actions, and so the Installer class tries to install the service all over again. This can be prevented by adding a Condition of NOT REINSTALL on the Install and Commit custom actions in the setup project. This way these won’t get called during a repair / reinstall.

Technorati tags:  ,  ,  

Leave a Reply

Your email address will not be published. Required fields are marked *