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), _
IsAssemblyDebugBuild(args(0)))
Else
Console.WriteLine(UsageString)
End If
Console.ReadLine()
End Sub
Private Function IsAssemblyDebugBuild(ByVal filepath As String) As Boolean
Return IsAssemblyDebugBuild( _
Reflection.Assembly.LoadFile(IO.Path.GetFullPath(filepath)))
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
Next
End Function