.Net framework version the assembly was created in

string assemblyPath = @”<exe/ dll path>”;

var assembly = Assembly.LoadFrom(assemblyPath);

var customAttributes = assembly.GetCustomAttributesData();

var dotnetFramework = customAttributes.FirstOrDefault(attr => attr.AttributeType.Equals(typeof(TargetFrameworkAttribute)));

var frameworkVersion = string.Empty;

if (null != dotnetFramework)

{

if (dotnetFramework.ConstructorArguments.Any())

{

// first argument is the name of the framework.

frameworkVersion = (string)dotnetFramework.ConstructorArguments[0].Value;

}

}

Console.WriteLine(“Framework Version: “ + frameworkVersion);

 

This code will give you the .Net framework version the dll/exe was created in.

 

I tested it for 4.5, 4.6.1 , 4.5.2 and gives the correct info.

 

Advertisements