View Single Post
  #6  
Old 01-23-2009, 10:59 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 5,749
This is approximately how VBP 6.2a located msbuild (the logic has changed quite a bit since then):

Code:
string frameworkPath = GetDotNetFrameworkPath();
if (frameworkPath.Length > 0)
{
	string exe = Path.Combine(frameworkPath, "msbuild.exe");
	if (File.Exists(exe))
		return exe;
}

private static string GetDotNetFrameworkPath()
{
	RegistryKey k = Registry.ClassesRoot.OpenSubKey(@"CLSID\{43CD41AD-3B78-3531-9031-3059E0AA64EB}\InprocServer32");
	if (k != null)
	{
		string ver = "";
		double largest = 0.5;
		foreach (string subkey in k.GetSubKeyNames())
		{
			RegistryKey s = k.OpenSubKey(subkey);
			if (s != null)
			{
				object o = s.GetValue("RuntimeVersion");
				if (o != null)
				{
					double f = double.Parse(((string)o).Substring(1, 3));
					if (f > largest)
					{
						largest = f;
						ver = (string)o;
					}
				}
			}
		}

		if (ver.Length > 0)
		{
			RegistryKey n = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");
			if (n != null)
			{
				object o = n.GetValue("InstallRoot");
				if (o != null)
					return Path.Combine((string)o, ver);
			}
		}
	}
	return "";
}
Reply With Quote