Getting the .NET Framework Path and Version

I came across a handy tip for getting the path to the current .NET Framework version and the version number. I had been using Reflection but this wasn't very satisfactory:

System.Reflection.Assembly.GetExecutingAssembly.Location

Here's a better way, as found in recipe 20.5 of C# Cookbook from O'Reilly:

System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory

You can get the version of the runtime using:

System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion 

BTW, this second edition of C# Cookbook has over a dozen solutions on using Generics in .NET 2.0. I'm still trying to get my head around generics. It's a bit intimidating when one listing alone (ReversibleSortedList class) goes on for 25 pages.

No Comments