You don't need or can have any special environment, but debugging of a Windows Service is not so easy.
One thing you can do it just compiling it under Visual Studio in place of deployment, start it in a regular way using the Service Controller, and then, in Visual Studio, use "Debug -> Attach Process". The execution will stop at some breakpoints you could set in advance, and then you can continue step be step debugging. This is described here:
http://msdn.microsoft.com/en-us/library/7a50syb3%28v=vs.110%29.aspx[
^].
This method is hard to debug the earlier steps of execution of a Windows Service process. To cover those steps, you can, say, create an artificial delays. Many things can be resolved by using logging. Please see:
http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.eventlog[
^].
I've used one much less usual and dedicated approach to debugging. I developed a special type of application which can work as both an interactive application and as the service, depending how it is hosted. If you start the application from the Shell, it is executed in an interactive mode, and if you start it from "Services" applet (by a Service Controller), it is executed as service. Important for debugging feature is: both modes use the same methods, which are designed to work in both environments. Moreover, for an interactive mode, I created a special console-like window (not a standard console, just based on some list box) to show logging information, by implementing dual logging mechanism (in service mode, it uses
EventLog
, see above).
For this technique, the key is the detection of the execution mode by such dual-mode application. This is done by using the static property
System.Environment.UserInteractive
:
http://msdn.microsoft.com/en-us/library/system.environment.userinteractive%28v=vs.110%29.aspx[
^].
This approach helped me to debug nearly all of the problems using just the interactive mode. The problems which were manifested only in the service mode also existed; so I fixed them using just the logging. It's important to note that the applications I developed using this techniques were extremely complicated. If the Service is not extremely complex, you could walk out doing nearly all debugging in the interactive mode.
[EDIT]
See also my past answer on my dual-mode Service application:
Configure Windows Service with UI[
^].
On the problem of the installation, see also:
How to install windows service programmatically[
^].
Please see also my other past answers on Windows Service creation and installation:
Configure Windows Service with UI[
^],
Windows services Error[
^],
http://msdn.microsoft.com/en-us/library/zt39148a.aspx[
^].
—SA