How to find out if a .NET assembly was compiled with the TRACE or DEBUG flag
Asked Answered
F

5

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?

Firstfoot answered 10/3, 2009 at 11:1 Comment(2)
With or without adding code to the assembly?Grafting
similars questions in Stackoverflow, one question, and many, many different answers: #654950 #799471 #195116 #51400 #890959Phrygian
A
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

Aperient answered 28/4, 2009 at 17:19 Comment(0)
A
4

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

Aligarh answered 10/3, 2009 at 11:48 Comment(0)
A
3
static bool IsDebug(){
 bool rv = false;
 #if DEBUG
 rv = true;
 #endif
 return rv;
}
Autostrada answered 10/3, 2009 at 11:9 Comment(1)
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.Firstfoot
D
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.

Deep answered 10/3, 2009 at 11:19 Comment(0)
J
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

Jungjungfrau answered 8/12, 2011 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.