dotnetornot – the conversation that became a tool
Several weeks ago, an IT friend of mine was telling me about a horrific tool that some vendors had given him. This tool had two distinctive features: it had dozens of DLLs packaged with it, and it was slow as hell. My friend wanted to ngen the DLLs in order to squeeze some performance out of the tool, but in a hilarious twist, it seemed that not all of the DLLs were .NET asemblies, and those that were .NET were built against different versions of the Framework. He asked me if there was any way to tell what version of .NET an assembly used; I replied “Using Reflection? Yeah, probably” and sent him the following C# code:
namespace dotnetornot
{
class Program
{
static void Main(string[] args)
{
System.Reflection.Assembly assm = null;
try
{
assm = System.Reflection.Assembly.LoadFrom(args[0]);
System.Console.WriteLine("This assembly uses .NET version {0}",
assm.ImageRuntimeVersion);
}
catch (System.BadImageFormatException bifex)
{
System.Console.WriteLine("Not a .NET assembly");
}
}
}
}
Copy-paste-compile, call it like “dotnetornot <path-to-file>”
Anyway, a couple nights ago, my friend was telling me about how he was dealing with this tool, and said “btw dotnetornot is amazing.” I had forgotten about it completely, but it seems he’s been using it to automate the process of calling the appropriate ngen on assemblies that support it. Nice
