I needed to figure out how the directory path to the .NET Framework so I could lauch a process (regasm.exe) from an assembly. You would think that the System.Environment class or the Environment.SpecialFolder enumeration. Keith Brown posted how you can find it using P/Invoke with mscoree.dll. Well, instead of making a P/Invoke call, I wanted an easier way to looking for it. Here's what I came up with:
namespace FrameworkPath
{
using System;
class Program
{
static void Main(string[] args)
{
Type objType = typeof(object);
string moduleName = objType.Module.FullyQualifiedName;
string frameworkPath = System.IO.Path.GetDirectoryName(moduleName);
Console.WriteLine(".NET Framework Path: {0}", frameworkPath);
Console.Write("Press to exit.");
Console.ReadLine();
}
}
}
Pretty straight forward.