Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created August 1, 2013 07:50
Show Gist options
  • Save tugberkugurlu/6129289 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/6129289 to your computer and use it in GitHub Desktop.
How to check if an assembly was built using Debug or Release configuration (ref: http://stackoverflow.com/questions/2186613/how-to-check-if-an-assembly-was-built-using-debug-or-release-configuration)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
namespace CheckIfDebugOrRelease
{
class Program
{
static void Main(string[] args)
{
Assembly assembly = Assembly.LoadFile(@"C:\Dev\Prv\Samples\CheckIfDebugOrRelease\CheckIfDebugOrRelease\lib\CheckIfDebugOrRelease.exe");
IEnumerable<Attribute> customAttributes = assembly.GetCustomAttributes();
IEnumerable<Attribute> debuggableAttributes = from attribute in customAttributes
let debuggableAttribute = attribute as DebuggableAttribute
where debuggableAttribute != null && debuggableAttribute.IsJITTrackingEnabled
select attribute;
if (debuggableAttributes.Any())
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("'{0}' has been compiled in Debug mode!", assembly.FullName);
}
else
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("'{0}' has not been compiled in Debug mode!", assembly.FullName);
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment