Getting the .NET Framework directory path

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)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s