views:

130

answers:

1

How to efficiently write code and debug windows service project in visual studio? Visual Studio gives

Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.

when I want to debug my code. It seems to me that it is inefficient to test the code. One has to install a service, start it, attach the debugger, test it, and then uninstall it.

Thanks, Gil.

+3  A: 

As the first comment mentioned there are many other items out there...but I wanted to put a little light on this as well.

  1. You can use a post build event to manage the process of installing after build etc, so that you don't have any effort needed there.
  2. You can use Debugger.Break() to be able to start debugging right away. This way you are not playing the "Attach" game.

These will at least get you going, and help reduce the "pain" you experience.

Mitchel Sellers
Can you expand upons the Debugger.Break suggestion? I'm not aware of this and play the Attach game... :(
Walter
Sure, in your init code put Debugger.Break(). That will trigger a popup for you to start debugging using Visual Studio!
Mitchel Sellers