I have a quick question: When I go to HELP->About in Visual Studio 2012, the window indicates that the version of .NET I'm using is 4.5.50709. However, when I execute the following code:
Console.WriteLine(Environment.Version);
I get version 4.0.30319.18034. What gives? In Troelsen's Pro C# 5 & .NET 4.5 Framework, on page 81 it states that the Version property returns an object representing the .NET platform version. Is this incorrect? The thread for a previous question indicated that this property returns the CLR version. If this is the case, what is the purpose of the Version object (as in, what is the use of knowing the CLR version as opposed to the framework version), and how do you actually get the framework version itself?
The version of .NET Framework (4.5 and later) installed on a machine is listed in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. If the Full subkey is missing, then .NET Framework 4.5 or above isn't installed.
Navigate to the Control Panel (Click here for instructions on how to access the Control Panel on Windows 10, 8, and 7 machines) Select Programs and Features (or Programs) In the list of installed applications, locate "Microsoft . NET Framework" and verify the version in the Version column to the right.
Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to determine the version of . NET installed and press Enter: reg query "HKLM\SOFTWARE\Microsoft\Net Framework Setup\NDP" /s.
The CLR (Common Language Runtime) version is 4.0.30319.18034. It starts with 4.0.30319 because .NET 4.5 is an in-place upgrade of the .NET 4.0 assemblies.
The 4.5 update completely replaces the .NET 4.0 runtime and leaves the actual version number set at v4.0.30319.
(source 1, source 2)
But your version number probably represents .NET 4.5 with some updates, as might be deduced from this list by user Daniel:
Here are some examples of runtime versions I've seen:
- 4.0.30319.1 = .NET 4.0 RTM
- 4.0.30319.269 = most common .NET 4.0 version we're seeing in the data collected from our users
- 4.0.30319.544 = another .NET 4.0 version that a small portion of our users have installed
- 4.0.30319.17626 = .NET 4.5 RC
- 4.0.30319.17929 = .NET 4.5 RTM
- 4.0.30319.18010 = current version on my Windows 8 machine
The major, minor and build version numbers didn't change, so I reckon they didn't think the difference between .NET 4.0 and 4.5 would be big enough to matter for most people. Applications for .NET 4.0 that expect some version 4.0.30319 still work as expected under .NET 4.5.
Whether you code for .NET 4.0 or 4.5, you are compiling against the exact same .NET assemblies. The only difference is that some new classes from .NET 4.5 are hidden when compiling against .NET 4.0 (as if they never existed). So the only reliable way to tell the difference between .NET 4.0 and 4.5 seems to be the rather hackish approach proposed by Christian.K in his post, that doesn't involve version numbers:
The
ReflectionContext
class seems to be totally new with the .NET framework 4.5 and conveniently lives inmscorlib
. So you could do something like this.public static bool IsNet45OrNewer() { // Class "ReflectionContext" exists from .NET 4.5 onwards. return Type.GetType("System.Reflection.ReflectionContext", false) != null; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With