11

Using C#, what is the best way to ask the .NET Runtime which version you are running under?

3 Answers 3

18

Use Environment.Version. This has the version number of the CLR currently running your code and is supported on all versions of the CLR.

Documentation

Sign up to request clarification or add additional context in comments.

1 Comment

This newer property is more accurate for after .NET Framework 4.5 System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription
5

It is important to be careful about asking which version of the framework is running, and which version of the runtime is running, as they can be different. Your title and body ask subtly different questions.

@JaredPar is right on the money with the runtime version.

For framework versions, check out this closely-related post: How to detect what .NET Framework versions and service packs are installed?

1 Comment

The latest installed version might not be the same as the current assembly is running under. Getting the current executing framework version should be easier than checking for installed versions. (but lack of answers in that regard points to that not being the case)
2
  • You can write a simple method for this purpose:

    public static void GetVersion() {   
     Environment.Version.ToString() }
    

The output is your .net version.

  • You can also find the installed versions in the following location:

    C:\WINDOWS\Microsoft.NET\Framework
    
  • If you are using Visual Studio, run Visual Studio commander from the start menu, and enter clrver , and it gives you the running version.

  • And for sure, you can always check your registry for that:

    HKEY_LOCAL_MACHINE \ software \ Microsoft \ Net Framework \
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.