Assembly ImageRuntimeVersion
Monday 6 March 2006
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.
Posted by
at 07:35 AM.
Permalink.
Copyright © Charles Cook.
Valid XHTML 1.0