How to tell if an existing assembly is Debug or Release build

Posted Thu, Jun 17 2004 12:27 by bill

When you build an assembly in Debug mode, the compiler adds the System.Diagnostics.DebbugableAttribute into the assembly’s attributes.  You can use this to determine if an assembly is a Debug build or Release build.  The following code is for a command line utility that just checks for that attribute in the specified assembly.

   Private Const UsageString As String = _
       "Checks to see if an assembly is a debug build." & _
        "The arguement should be the path of the assembly  to check"

   Sub Main(ByVal args() As String)
      If args.Length = 1 Then
         Console.WriteLine("File {0} is Debug Build = {1} ", _
args(0), _
      End If
   End Sub

   Private Function IsAssemblyDebugBuild(ByVal filepath As String) As Boolean
      Return IsAssemblyDebugBuild( _
   End Function

   Private Function IsAssemblyDebugBuild(ByVal assemb As Reflection.Assembly) As Boolean
      For Each att As Object In assemb.GetCustomAttributes(False)
         If TypeOf att Is Diagnostics.DebuggableAttribute Then
          Return CType(att, Diagnostics.DebuggableAttribute).IsJITTrackingEnabled
         End If
   End Function

Filed under:


# re: Determine if a .NET Assembly is Release or Debug

Wednesday, June 16, 2004 6:29 PM by TrackBack

# re: How to tell if an existing assembly is Debug or Release build

Friday, June 18, 2004 2:39 AM by bill

v1.x of the C# compiler adds DebuggableAttribute(false, true) even for non-debug builds, unless you compile with /optimize. So just checking if DebuggableAttribute is present might not give you the expected result.

# re: How to tell if an existing assembly is Debug or Release build

Friday, June 18, 2004 3:49 AM by bill

Thanks Mattias !

Looks to me like a bug in the C# compiler ;)

Anyway, I modified the code so as now it returns the IsJITTrackingEnabled value. hopefully that covers all C# quirky builds

# DOTNET : Outil de test de mode de compilation

Tuesday, February 07, 2006 4:07 AM by F___ French Blog

A la suite de l'article posté sur les options de compilation :

Le debugging en .NET


# Was an Assembly Built in Debug or Release Mode?

Monday, June 26, 2006 1:41 PM by C# Distilled

Sometimes you find yourself wondering if an assembly was compiled with or without the /debug compiler...