Cook Computing

Assembly ImageRuntimeVersion

March 5, 2006 Written by Charles Cook

I sometimes need to determine the version of the CLR an assembly was built against. I use the following program:


using System;
using System.Reflection;
using System.IO;

class Program
{
  static int Main(string[] args)
  {
    try
    {
      if (args.Length != 1)
        throw new Exception("usage: clrbuildver file");
      string absPath = Path.GetFullPath(args[0]);
      Assembly asmbly = Assembly.LoadFile(absPath);
      Console.WriteLine(asmbly.ImageRuntimeVersion);
    }
    catch (Exception ex)
    {
      Console.Error.WriteLine(ex.Message);
      return 1;
    }
    return 0;
  }
}

This uses the Assembly ImageRuntimeVersion property. One caveat though, according to Suzanne Cook:

By default, it's [ImageRuntimeVersion] the version that the image was compiled against. However, that's not necessarily what it will be, since compilers can be configured to put any string there.