Click here to Skip to main content
15,892,746 members
Articles / Programming Languages / C#

(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.8K   1  
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 =...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
3 Feb 2012SoftwareMonkeys
While I think alternative 3 could be quite useful I often have access to the assembly name and not the actual file name.For example the assembly name might be:Company.ProductWhereas the file name might be:Company.Product.dllThere are times when I'll fully qualify a class such...
Please Sign up or sign in to vote.
24 Feb 2012Andreas Gieriet
I prefer the [Conditional("DEBUG")] attribute over #if DEBUG.This is especially advised for your logging example.E.g.[System.Diagnostics.Conditional("DEBUG")]private void Validate() { /* check instance integrity */ }or[System.Diagnostics.Conditional("DEBUG")]public static...
Please Sign up or sign in to vote.
29 Jan 2012Pablo Aliskevicius
You can make it a bit shorter: public virtual bool IsDebug { get { #if (DEBUG) return true; #else return false; #endif } }Thanks for sharing,
Please Sign up or sign in to vote.
4 Feb 2012SoftwareMonkeys 4 alternatives  
Sometimes, it's useful to know whether you're running in debug or release mode so you can do extra work during debugging and skip it during release. This class makes that as simple as possible.

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