How do I determine if my app was compiled as "release" instead of "debug"? I went to VS 2008 Project Properties > Build and set the configuration from Debug to Release but I noticed no change? This is an ASP.NET project.
-
similars questions in Stackoverflow, one question, and many, many different answers: http://stackoverflow.com/questions/654450/programatically-detecting-release-debug-mode-net http://stackoverflow.com/questions/798971/how-to-idenfiy-if-the-dll-is-debug-or-release-build-in-net http://stackoverflow.com/questions/194616/how-to-tell-if-net-app-was-compiled-in-debug-or-release-mode http://stackoverflow.com/questions/50900/best-way-to-detect-a-release-build-from-a-debug-build-net http://stackoverflow.com/questions/890459/asp-net-release-build-vs-debug-build – Kiquenet Feb 03 '11 at 19:51
4 Answers
If you want to know if the dll was built in Debug mode, with the debug attributes, then your best bet is reflection.
Taken from "How to tell if an existing assembly is debug or release":
Assembly assembly = Assembly.GetAssembly(GetType());
bool debug = false;
foreach (var attribute in assembly.GetCustomAttributes(false)){
if (attribute.GetType() == typeof(System.Diagnostics.DebuggableAttribute)){
if (((System.Diagnostics.DebuggableAttribute)attribute)
.IsJITTrackingEnabled){
debug = true;
break;
}
}
}
This will get the assembly that is calling that code (in effect itself), and then set the debug boolean to true if the assembly was compiled in debug mode, otherwise it's false.
This could easily be dropped into a console app (as in the linked example), and then you pass in the path of the dll/exe you want to check. You would load the assembly from a path like this:
Assembly assembly =
Assembly.LoadFile(System.IO.Path.GetFullPath(m_DllPath.Text));

- 26,785
- 5
- 80
- 117
For one in Web.config debug will be set to true, however you can actually set this in a release application too.
In debug however defines like DEBUG are set, so it's simple to do:
bool is_debug;
#ifdef DEBUG
is_debug = true;
#else
is_debug = false;
#endif

- 29,197
- 4
- 84
- 98
-
debug is set in the Web.config only if you explicitly set it, or you hit F5 to run the website and allowed it to change the config file. This setting is not an indicator of what *build configuration* is selected. – Gromer May 21 '09 at 04:28
-
You need to look for more than IsJITTrackingEnabled - which is completely independent of whether or not the code is compiled for optimization and JIT Optimization.
Also, the DebuggableAttribute is present if you compile in Release mode and choose DebugOutput to anything other than "none".
Please refer to my posts: How to Tell if an Assembly is Debug or Release and How to identify if the DLL is Debug or Release build (in .NET)

- 1
- 1

- 7,305
- 2
- 52
- 41