Álvaro García
Álvaro García

Reputation: 19396

how to know the version of .NET? or convert a project from 4.0 to 4.5.1?

I had a project which first target was .NET4.0 but now I change the project to 4.5.1, and I would like to know how to check the version of .NET, because I run the application in a fresh win7 and the application runs.

I try to use this code to check the version of .NET that is used:

string version = System.Reflection.Assembly
                     .GetExecutingAssembly()
                     .GetReferencedAssemblies()
                     .Where(x => x.Name == "System.Core").First().Version.ToString();

            MessageBox.Show(version);

And the result is 4.0.0.0, so how I am thinking that the application is still 4.0. How can I change the target of the application?

Thanks.

Upvotes: 1

Views: 385

Answers (1)

Satyajit
Satyajit

Reputation: 2210

Check this if it helps. I have tested it in a web application. It's showing correct values.

var targetFrameWork =  Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute),false);
var frameWork = ((System.Runtime.Versioning.TargetFrameworkAttribute)(targetFrameWork[0])).FrameworkName;

It returns '.NETFramework,Version=v4.5'.

Note:

Environment.Version returns '4.0.30319.18444'.

    System.Reflection.Assembly.GetExecutingAssembly()
                             .GetReferencedAssemblies()
                             .Where(x => x.Name == "System.Core").First().Version.ToString();

It returns '4.0.0.0'.

Upvotes: 1

Related Questions