Is it possible to run specific code only when I am debugging the program via the debugging tools of Visual Studio?
If I use #if DEBUG
or Conditional(“DEBUG”)
the code is still triggered when running the .exe in the /Debug directory.
Is it possible to run specific code only when I am debugging the program via the debugging tools of Visual Studio?
If I use #if DEBUG
or Conditional(“DEBUG”)
the code is still triggered when running the .exe in the /Debug directory.
The #if DEBUG
is for Conditional Compilation, it does not affect execution at runtime.
Instead use Debugger.IsAttached
to branch at runtime.
Just to make it clear, the statements beginning with a hashtag are pre-processor directives. These directives are not present in the Translation Unit; thus these conditional statements do not exist in the compiled file.
EDIT It seems that this whole translation unit thing doesn't apply for C#