Finding the Path to the Current Framework Version




Finding the Path to the Current Framework Version

Problem

You need the path to where the version of the .NET Framework you are running on is located.

Solution

Use the GetruntimeDirectoryRuntimeDirectory method (implemented in System.Runtime.InteropServices.RuntimeEnvironment) to return the full path to the folder that the current version of .NET is installed in:

	public static string GetCurrentFrameworkPath()
	{

	     return
	System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
	}

Discussion

There are many reasons why you might want to know the current framework path, including:

  • Manually loading the configuration files in the config directory to check settings

  • Dynamically adding references for system components in a code generator

The list could go on and on. Since the method to get to the path is pretty far down a namespace chain (System.Runtime.InteropServices.RuntimeEnvironment), it is provided for your programming convenience.

See Also

See the "Version Class" and "Version.ToString Method" topics in the MSDN documentation.