C # get framework / runtime version from application with Assembly

I am trying to check which version of the framework is being used by another .NET application through the assembly. I found two ways to get the version of the framework (first through ImageRunetimeVersion and with FullName of the assembly), but I get two different values ​​from it, and I don’t know what is correct:

        Assembly ass = Assembly.LoadFrom(autPath);            
        string imageRuntimeVersion = ass.ImageRuntimeVersion;
        Console.WriteLine("ImageRunetimeVersion: " + imageRuntimeVersion);
        Console.WriteLine("FullName: " + ass.FullName);

        Console.WriteLine("");            
        Console.WriteLine("----");
        Console.WriteLine("Referenced Assemblies: ");
        Console.WriteLine(""); 

        AssemblyName[] referencedAssemblies = ass.GetReferencedAssemblies();
        foreach (AssemblyName a in referencedAssemblies)
        {
            Console.WriteLine(a.FullName);
        }

if I am going to test this using my application and, for example, paint.net, the results:

As you can see, I can’t say which “version” is correct. The biggest problem is that if I'm going to take a look at my project properties for my .net application, the target platform is 3.5, not 2.0 or 1.0 -

+3
source share
2 answers

, - . -, FullName . , .NET framework. , FullName .

imageRuntimeVersion - CLR. , 2.0 .NET 2.0, 3.0 3.5. , , ( ).

SO : .Net

, , . , , , .

+5

TargetFramework CLR.

,

CLR 4.0 TargetFramework:.NET 4.0 .NET 4.5

TargetFrameworkAttribute http://www.lucbos.net/2011/08/get-targetframework-for-assembly.html

. TargetFrameworkAttribute .NET 4.0.

    var targetFramework = "Unknown";
    var targetFrameworkAttributes = assembly.GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), true);
    if (targetFrameworkAttributes.Length > 0)
    {
        var targetFrameworkAttribute = (TargetFrameworkAttribute)targetFrameworkAttributes.First();
        targetFramework = (targetFrameworkAttribute.FrameworkDisplayName);
    }
+1

All Articles