It seems to be an easy question but there are also some traps. The reason is that theoretically it is possible to make a difference between CLR Version and Framework Version. In the times of .NET 3.5 it was usual to keep the CLR version still on version 2.0 because there are only new libraries added to the framework.
But “.NET Framework 4.5” usually means the combination of the “newest” frameworks and CLR Version. Although .NET 4.5 is an “in-place-upgrade” for .NET 4.0 what makes the whole situation even more complicated.
Good entrance (and I’m going to talk about this later again) is the post of Scott Hanselman:
Easy check for: Is the .NET Framework Version 4.5 installed or not?
To clarify what version you’ve got installed you will find an helpful hint from the registry at the pad “Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full”
In my cases it is: Jepp - .NET 4.5. Unfortunately this test will only work if you are the system-admin and in full control of the system and the applications.
Does my application run with .NET 4.5?
This doesn’t mean if the application is “compatible” to .NET 4.5 but if the application is able to use the .NET 4.5 features.
It’s kind of difficult to answer this question since this depends on the app.config or the web.config and if the IIS is in the game you have to configure the AppPool properly.
If you read the Hanselman Post you are now going to get a very short version of it
If you run a Desktop Application without the correct framework version in the supportedRuntime Element of the app.config you are going to receive an error message. That’s how I tell my Runtime that my app needs .NET 4.5:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> </configuration>
When there is no .NET 4.5 that’s your error message:
There is a similar element for Web-Application in the web.config:
If the Runtime the TargetFramework needs isn’t there you will see another error message if you try to run the Webapp.
Bets Practice: Feature Detection during the runtime
<configuration> <system.web> <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" /> </system.web> </configuration>
Since the framework always includes several libraries and every library has a different version number and a different Runtime you might test properly if there is something like a special class for example.