Install .NET Windows Service with Visual Studio Setup Wizard or Project

I've done this a couple of times but I still tend to forget at times so
I might as well post here for me and hopefully someone else's reference.

To create a Windows Service see this article by Ken Getz : Windows Services: New Base Classes in .NET Make Writing a Windows Service Easy

There
are a number of ways to install a windows service, one of which is
using installutil.exe but this post will be using Setup Project which
for me is a little easier to implement: [more]

Was working with VS2005 for this but I think the same things with VS2003 and will update this one for VS2008 soon.

Using SetUp Wizard template
1) open your Windows Service project in VS
2) add a Setup project to your solution

  • File > Add Project > New Project > Setup and Deployment Projects > Setup wizard
  • Set the location appropriate for your situation and click on OK

3) in the Setup wizard, skip page 1.
4) On page 2 (of 5) select "Create a Setup for a Windows application."
5) On page 3, select "Primary output from ."
6) On page 4, click on Finish.
7) The final step (a crucial one) is to add a custom action to run the code in the installer class you added to your project.

  • Right click on the setup project (Solution Explorer)
  • View > Editor > Custom Actions.
  • Right-click on the Install node in the Custom Actions treeview.
  • In the Select Item in Project dialog, make sure Application Folder is selected, and click on OK.
  • Click on OK again to select the "Primary output from " option. You should now see this as a child node of the Install node.

That's
all you have to do. Rebuild both the project and the setup project, run
the installation, and the service should be installed as a Windows
service.

Of course, this scenario doesn't deal with getting the
service started. Even if you've set the ServiceInstaller component's
StartType property to Automatic, you have to reboot the computer to
start the service. (Or, you can use the services.msc applet and start
it yourself.)


——–
Another alternative is to use the Setup Project instead of Setup Wizard.
1) Same as step 1 above
2) add a Setup project to your solution

  • file > Add Project > New Project > Setup and Deployment Projects > Setup Project (rather than Setup Wizard as above)
  • set the location appropriate for your situation and click on OK

3) Right click on the Setup Project (in Solution Explorer)

  • Add > Project Output > Select your Windows Service in the Project dropdown
  • Select Primary Output in the list below it.
  • Click OK

4) The final step (a crucial one) is to add a custom action to run the code in the installer class you added to your project.

  • Right click on the setup project (Solution Explorer)
  • View > Editor > Custom Actions.
  • Right-click on the Install node in the Custom Actions treeview.
  • In the Select Item in Project dialog, make sure Application Folder is selected, and click on OK.
  • Click on OK again to select the "Primary output from " option. You should now see this as a child node of the Install node.

Basically the difference is how the Output was specified to include the "Primary output from .".

Assuming there's nothing wrong with your VS, .NET framework then this should be easy.

Get Free Email Updates!

Signup now and receive an email once I publish new content.

I will never give away, trade or sell your email address. You can unsubscribe at any time.