views:

2145

answers:

3

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?

+2  A: 

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

David Stratton
When VS is available on the machine there is no problem in installing the service. If VS is not available how we can install the service which is developed in .Net3.5?
srikanthv
The setup project, when built, creates an installer (.msi file). Copy it (and the setup.exe that will also be in that project's folder) to the machine you want to install it on and run it like any setup program. One thing to note is that you may need to right-click on the setup project to and choose "build". By default, setup projects don't build when you choose "Build Solution". This annoying default can be overridden in the configuration manager.
David Stratton
A: 

If you've been using InstallUtil.exe to install your Windows service, then that means you've added a ProjectInstaller component to your service. All the InstallUtil.exe does is use reflection to find the installer component embedded in your service and execute some methods on it. Due to this, you can modify your Windows service to install and uninstall itself, i.e., you no longer have to depend on InstallUtil.exe being available on the target machine. I've been using this successfully for several months now. Just follow the step-by-step I provided here. The idea originally belongs to Marc Gravell and this post.

Matt Davis
+1  A: 

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.

Kelsey