If you have code that you want to run only while debugging in Visual Studio, you can detect it if you are running in its hosting process, which is enabled by default.
#if DEBUG
if(AppDomain.CurrentDomain.FriendlyName.EndsWith("vshost.exe"))
{
// Perform whatever tasks depend on running inside the Visual
// Studio debugger.
}
#endif
While it does provide several features not otherwise available, you might have a reason to disable it (such as a corrupted vshost.exe file). To do so, uncheck the last box (shown checked here) on the Debug tab in the Project Properties window.