Is there a variable or a preprocessor constant that allows to know that the code is executed within the context of Visual Studio?
There is the DesignMode property for Components. It is handy when you use the Design Viewer of VS.
But when you talk about debugging in Visual Studio you need to use the Debugger.IsAttached property. Then, you can use
#if DEBUG #endif
too