Determine debug / release mode in a published DLL? Without #DEBUG

I have a component that can be referenced in some projects (eg. Component.dll ). I publish it, of course, in release mode.

In another project (eg. Project.exe ), I refer to Component.dll .
If I build Project.exe in Debug mode, is there a way to find out in my Component.dll library?

To learn more: if I have a class and method named Test inside Component.dll . Can I do something like:

 public void Test(){ if(Debug.IsInDebugMode) ... } 

Keep in mind that Component.dll is built into release mode.

+6
c # build-process
source share
1 answer

Whether your code is inline in Release or Debug mode doesn't really matter. The generated IL is almost the same. The version of Debug will have the attribute used by jitter to set the default values ​​for compilation, this attribute is not in yours. The next thing that matters is exactly how you debug or launch your application. An important parameter is "Tools + Options", "Debug", "General", "Disable JIT optimization when loading the module". It is checked by default.

Now the question is whether your application is being launched by the debugger or not. It is easy to find out, use the System.Diagnostics.Debugger.IsAttached property. When false, the machine code generated from your IL will be optimized by jitter. A degenerate case attaches a debugger after the code has started. It is important that this does not matter to you.

+5
source share

All Articles