Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a Windows service developed in .NET 3.5?

I have developed a Windows service using Visual Studio 2008. I want to install that service in a machine where Visual Studio is not installed, but .NET 3.5 is installed.

Generally InstallUtil.exe shall be used for installing a Windows Service, but the InstallUtil.exe utility is not available in .NET 3.5. When I tried installing that service using .NET 2.0, the service is getting displayed in the list of services but when starting the service Windows Service error 1053 is coming. How we can avoid this problem and successfully install the service?

like image 711
srv Avatar asked Oct 09 '09 03:10

srv


2 Answers

It's actually really simple as I just did it a couple of days ago for something I made.

So in your service project you want to:

  1. In the solution explorer double click your services .cs file. It should bring up a screen that is all gray and talks about dragging stuff from the toolbox.
  2. Then right click on the gray area and select add installer. This will add an installer project file to your project.
  3. Then you will have 2 components on the design view of the ProjectInstaller.cs (serviceProcessInstaller1 and serviceInstaller1). You should then setup the properties as you need.

Now you need to make a setup project. The best thing to do is use the setup wizard.

  1. Right click on your solution and add a new project: Add > New Project > Setup and Deployment Projects > Setup Wizard
  2. On the second step select "Create a Setup for a Windows Application."
  3. On the 3rd step, select "Primary output from..."
  4. Click through to Finish.

Now you need to edit your installer to make sure the correct output is included.

  1. Right click on the setup project in your Solution Explorer.
  2. Select View > Editor > Custom Actions.
  3. Right-click on the Install action in the Custom Actions tree and select 'Add Custom Action...'
  4. In the "Select Item in Project" dialog, select Application Folder and click OK.
  5. Click OK to select "Primary output from..." option. A new node should be created.
  6. Repeat steps 4 - 5 for commit, rollback and uninstall actions.

Now just build your installer and it will produce an MSI and a setup.exe. Choose whichever you want to use to deploy your service.

like image 126
Kelsey Avatar answered Oct 18 '22 09:10

Kelsey


There's a Microsoft KB on this for .Net 2.0 and VS2005. The procedure is exactly the same in .Net 3.5 and VS2008.

http://support.microsoft.com/kb/317421

And here's a nicer article with pictures to make it clearer. (Sometimes the KB's aren't as friendly as tutorials you can find elsewhere.)

http://aspalliance.com/1316_Working_with_Windows_Service_Using_Visual_Studio_2005.3

like image 20
David Avatar answered Oct 18 '22 07:10

David