Tell Debug and Release files apart

R

Rene

Is there a way to tell if an assembly was compiled on Debug or Release mode?
I tried viewing the file usin Ildasm but did't notice any special comment
line or something that would tell me if it was Debugged or Released.

Thanks.
 
J

jmcgrew

For assemblies that you control, you could put a custom attribute (that
you define) on the assembly inside a conditional compilation block:

#if DEBUG
[assembly: CompilationMode("Debug")]
#else
[assembly: CompilationMode("Release")]
#endif

Then you could use reflection to load the assembly and get a list of
its attributes, or just look at the assembly manifest with ILDASM.

Jesse
 
R

Rene

Say that your coworker compiled a dll for you and sent it over to you via
email. The file does not have any attributes, comment or anything else put
in by your coworker to tell you if the file was created as debugged or
released.



When you tried to contact him to ask him if the dll was compile on Debug or
Release mode you are not able to reach him. It is very important that you
find out how the file was compiled otherwise the world could cease to exist.
What do you do?
 
J

jmcgrew

Some brief experimentation suggests that the compiler automatically
adds a System.Diagnostics.DebuggableAttribute to the assembly when it's
compiled in debug mode (csc /debug+).

Also, debug mode usually means optimizations are off, and you can spot
an unoptimized method because it'll be full of "nop" instructions.

Jesse
 
R

Rene

Thanks, any chance you could tell me were can I see this
"System.Diagnostics.DebuggableAttribute" attribute?



Is this something you can see using Ildasm? I open a Debugged file using
Ildasm and I just can't find this Attribute, I must be missing something
really obvious.



Thanks.
 
C

Carlos J. Quintero [VB MVP]

Hi Rene,

You can use the code below from within a running assembly (VB.NET, translate
it to C#). For an external assembly, use objAssembly =
System.Reflection.Assembly.LoadXXX(...)

Dim objAssembly As System.Reflection.Assembly

objAssembly = System.Reflection.Assembly.GetExecutingAssembly()

If objAssembly.GetCustomAttributes(GetType(DebuggableAttribute),
True).GetLength(0) > 0 Then
MessageBox.Show("Debug")
Else
MessageBox.Show("Release")
End If

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top