Assume that you want to use csc.exe or some other framework tools and need access to the framework directory.
A lot of references on web suggest using the RuntimeEnvironment.GetRuntimeDirectory() function, the problem with this function is that it’ll give you the path of the executing CLR version, not the .Net framework path. So, assuming that you need access to C# compiler for the .Net 3.5 framework the call to RuntimeEnvironment.GetRuntimeDirectory() will return the wrong version folder and you’ll end up using the older version of the compiler.
To get the latest framework version folder for a CLR use the Microsoft build utilities as follows:
using Microsoft.Build.Utilities; ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.VersionLatest)