Click here to Skip to main content
15,881,380 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

(C#) Determining whether the current build mode is Debug or Release

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
1 Feb 2012CPOL 15.7K   1   3
Have a look this one, I just wrote: Accurate way to tell if an assembly is compiled in debug or release mode in c#[^] public static bool IsInDebugMode(string FileName) { var assembly = System.Reflection.Assembly.LoadFile(FileName); var attributes =...
Have a look this one, I just wrote: Accurate way to tell if an assembly is compiled in debug or release mode in c#[^]


C#
public static bool IsInDebugMode(string FileName)
{
    var assembly = System.Reflection.Assembly.LoadFile(FileName);
    var attributes = assembly.GetCustomAttributes(typeof(System.Diagnostics.DebuggableAttribute), false);
    if (attributes.Length > 0)
    {
        var debuggable = attributes[0] as System.Diagnostics.DebuggableAttribute;
        if (debuggable != null)
            return (debuggable.DebuggingFlags & System.Diagnostics.DebuggableAttribute.DebuggingModes.Default) == System.Diagnostics.DebuggableAttribute.DebuggingModes.Default;
        else
            return false;
    }
    else
        return false;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager www.xnlab.com
Australia Australia
I was born in the south of China, started to write GWBASIC code since 1993 when I was 13 years old, with professional .net(c#) and vb, founder of www.xnlab.com

Now I am living in Sydney, Australia.

Comments and Discussions

 
GeneralAh that could be a useful little function. Thanks for postin... Pin
SoftwareMonkeys2-Feb-12 19:30
SoftwareMonkeys2-Feb-12 19:30 
GeneralThis is the way to go - no guessing but asking the codes met... Pin
johannesnestler1-Feb-12 4:28
johannesnestler1-Feb-12 4:28 
GeneralReason for my vote of 5 Yes, this is the way to go! Pin
johannesnestler1-Feb-12 4:26
johannesnestler1-Feb-12 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.