I have a referenced library, inside there I want to perform a different action if the assembly that references it is in DEBUG/RELEASE mode.
Is it possible to switch on the condition that the calling assembly is in DEBUG/RELEASE mode?
Is there a way to do this without resorting to something like:
bool debug = false;
#if DEBUG
debug = true;
#endif
referencedlib.someclass.debug = debug;
The referencing assembly will always be the starting point of the application (i.e. web application.
One way that could work for most people is to simply open the DLL/EXE file with Notepad, and look for a path, for example search for "C:\" and you might find a path such as "C:\Source\myapp\obj\x64\Release\myapp. pdb", the "Release" shows that the build was done with Release configuration.
The accepted answer is correct. Here's an alternative version that skips the iteration stage and is provided as an extension method:
public static class AssemblyExtensions
{
public static bool IsDebugBuild(this Assembly assembly)
{
if (assembly == null)
{
throw new ArgumentNullException(nameof(assembly));
}
return assembly.GetCustomAttribute<DebuggableAttribute>()?.IsJITTrackingEnabled ?? false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With