Everybody working on MS platform understand what pain was it to write the Windows services before .NET platform. Though .NET takes care a lot of things on Windows Services development, we do not have sufficient power of debugging enhanced. I wanted to have some methods to do the same. Here is the jist of what I found, though it looks a kind of scattered but that is it and is much better than I found it.
Method 1 :
The this one really speaks about debugging them in-proc using a work around of Dummy Service.
"Attaching to the service's process allows you to debug most but not all of the service's code; for example, because the service has already been started, you cannot debug the code in the service's OnStart method this way, or the code in the Main method that is used to load the service. One way to work around this is to create a temporary second service in your service application that exists only to aid in debugging. You can install both services, and then start this "dummy" service to load the service process. Once the temporary service has started the process, you can then use the Debug menu in Visual Studio .NET to attach to the service process."
Sometimes it does not make any sense to have some more code written just to debug some code. This is bit useful and a sure method of testing that the debugging works.
Method 2 :
This one allows you to debug the OnStart using the some different line of code and explicitly calling the OnStart Method, which I used to debug.
Writing a small main routine and then working it out, makes sense but in this case the service does not remain a service, when I tried to work this out, I could debug the service but it lost the track of VSS attached with this. Shashi says this might be because of adding the main routine in the program it changed the type of the project and then it lost the track of VSS. Doesn't this mean my project is wasted now. Remember after you remove the main routine back to the original, does not mean the project type is changed back to OS service again.
Method 3:This one is for the reference, I could start the debugger as specified by the article, instead of MSVC, I added the fully qualified DEVENV.exe. This opens a new Solution for debugging offcourse it does not have any code in that to put the break points and to step-in. It even overrides the 30 second limit of service startup. MSDN does not speak how to attach an existing solution/Project to this solution, or opening an existing solution to debug.
How can I attach the PDB file or the solution so that I can debug the same? This is a valid request for all of the world of developers (should I say debuggers?).