Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

How to find out build mode(Release or Debug)

Is there anyway to determine the build mode from the DLL alone? I know if you have pdb file in your bin, then the project was build in Debug mode. But can we determine this from metadata where I have access to source files?

thanks in advance

Thursday, February 26, 2004

From the Project | Properties dialog box go to Configuration Properties - Build.  The top item on the right will be Conditional Compilation Constants.  By default the value of this property will be TRACE;DEBUG for debug builds and just TRACE for release builds.

You can use code similar to the following to detect the build mode at runtime:

bool runtime = false;

#if( DEBUG )
    runtime = true;

Len Weaver
Thursday, February 26, 2004

The question was about determining the build mode from the DLL alone... outside of Visual Studio, and without modifying the code.

I don't know of any way to do that. I thought ILDASM could do it but there doesn't seem to be a debug flag indicator.

Loading an executable without symbols into cordbg gives me the appropriate message but I don't know if that's just because the PDB is missing.

Chris Nahr
Thursday, February 26, 2004

sorry for the typo. it should have been like this

"But can we determine this from metadata where I DO NOT have access to source files?"

Yes I tried the ILDASM also but could not figure it out.

Thursday, February 26, 2004

Let's back up a sec.  Why do you want to do this?

Rick Childress
Friday, February 27, 2004

You can tell by looking at the IL for the manifest of your assembly / module and checking for the existence of the following:


This is explained in Chapter 16 of "Inside Microsoft .NET IL Assembler", which is an excellent reference for this sort of thing.

I verified it by building a retail and debug assembly and checking for the above attribute in the resulting IL using ILDASM.

Mike Treit
Friday, February 27, 2004


The reason is:

The application was running fine initially and but after the last change by different team, it was visibly slow and I was wondering whether it was accidentally built with "Debug" mode and only the dll was copied into production \bin directory.

Mike, I will try your approach and thanks for sharing.

Saturday, February 28, 2004

To avoid this problem, I have created NAnt build scripts that include the word "Debug" or "Release" in the title of the assembly.  But you can achieve this using VS.NET, too.

Using the previous tips in this discussion, you could simply #ifdef on the DEBUG setting and set attributes in the AssemblyInfo file accordingly.

Note: you can have PDB files in your release builds, too.

Bernard Vander Beken
Tuesday, March 2, 2004

It's true that U can have pdb files even if U select to compile in Release mode.
Then what the difference between a dll generated in Debug mode and Release mode ?
Is it only the 'Optimize Code' flag ?

Narendra Naidu
Sunday, March 14, 2004

*  Recent Topics

*  Fog Creek Home