sad_robot sad_robot - 1 month ago 16
C# Question

#if DEBUG directive in compiled class library

I am going to use #if DEBUG directive in a class library. The compiled ClassLibrary.dll will be used in a separate Application.exe.

Will my debug code from this class library be executed in the following situations?


  1. library is compiled in DEBUG mode, application is compiled in RELEASE

  2. library is compiled in RELEASE, application is compiled in DEBUG


Answer

A compiler directive is interpreted at compile time and not at runtime. Therefore it does not matter, if the using application is compiled in RELEASE or DEBUG mode. Therefore

1.) library is compiled in DEBUG mode, application is compiled in RELEASE => Yes

2.) library is compiled in RELEASE, application is compiled in DEBUG => No

Comments