I have done this many times in the past, depending on how the program works. I think that the easiest way is done with the ifDEBUG preprocessor directive around Debugger.Launch () so that when you build a project optimized for calling Debugger.Launch (), it will not be compiled into the assembly.
One of the ways we also did this task with System.Windows.Forms.MessageBox.Show ("attach"), which allowed us to manually attach to the debugger whenever the "attach" dialog was displayed.
, , - . , , ServiceBase.Run , - , , / .