10

Is there any way to find out if an assembly has been compiled with the TRACE or DEBUG flag set without modifying the assembly?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ralf
  • 101
  • 1
  • 3
  • With or without adding code to the assembly? – StingyJack Mar 10 '09 at 11:11
  • 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:52

5 Answers5

6

The only best way to do is check the compiled assemblies itself. There is this very useful tool called '.NET Assembly Information' found here by Rotem Bloom. After you install this it asociates .dll files to open with itself. After installing you can just double-click on the Assembly to open with it and it will give you the assembly details as displayed in the screenshop below. There you can identify if it's debug compiled or not.

alt text http://ruchitsurati.net/myfiles/asm_info.jpg

alt text
(source: ruchitsurati.net)

LinkText: http://www.codeplex.com/AssemblyInformation

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137
4

How to Programmatically Detect if an Assembly is Compiled in Debug or Release mode from Scott Hanselman.

Nick
  • 2,555
  • 1
  • 20
  • 18
3
static bool IsDebug(){
 bool rv = false;
 #if DEBUG
 rv = true;
 #endif
 return rv;
}
nothrow
  • 15,882
  • 9
  • 57
  • 104
  • Well thanks, but I am looking for a way to find out without modifying the assembly. I want to instpect an already compiled assembly preferably with some command line tool. – Ralf Mar 10 '09 at 11:15
1

There is probably no generic way. However, you could look for references to Assert and Debug from the System.Diagnostics namespace. Presence of those will indicate that the DEBUG flag was set.

The same holds for Trace and the TRACE flag.

Obviously this won't work if the source code does not use types from these namespaces.

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
1

The "IsDebug" app mentioned above, actually has a bug in it where it doesn't reflect on the correct DubuggableAttributes. It incorrectly assumes that if the DebuggableAttribute is present, then the assembly is not JIT Optimized. I've provided a correct implementation on my blog at:

How to Tell if an Assembly is Debug or Release

Dave Black
  • 7,305
  • 2
  • 52
  • 41