Search code examples
c#debuggingrelease-management

Do debugging attributes such as [DebuggerDisplay] still get compiled into Release binaries?


Having recently learned of the DebuggerDisplay attribute, I've found it quite useful. However, one thing that surprises me is that it doesn't have a [ConditionalAttribute("DEBUG")] attribute attached to it. Is there some way to force this or is it a bad idea to try? Or does it not matter for some other reason?


Solution

  • The [ConditionalAttribute("DEBUG")] is only used for optimising out method calls.

    If you really want to remove these from your builds you can use #ifdef so that the code is only compiled in release mode.

    One thing to bear in mind is that you can still debug binaries in release mode, as long as you have the pdb files it shouldn't matter. Release mode just clears up variables sooner and applies some compiler optimisations