3 using System.Diagnostics;
5 using System.Reflection;
6 using System.Runtime.InteropServices;
10 static class MonoToolsLocator
12 public static readonly string Mono;
13 public static readonly string CSharpCompiler;
14 public static readonly string VBCompiler;
15 public static readonly string AssemblyLinker;
17 // TODO: Should be lazy
18 static MonoToolsLocator ()
20 var gac = typeof (Environment).GetProperty ("GacPath", BindingFlags.Static | BindingFlags.NonPublic);
21 var getGacMethod = gac.GetGetMethod (true);
22 var GacPath = Path.GetDirectoryName ((string) getGacMethod.Invoke (null, null));
24 if (Path.DirectorySeparatorChar == '\\') {
25 string processExe = Process.GetCurrentProcess ().MainModule.FileName;
26 if (processExe != null) {
27 string fileName = Path.GetFileName (processExe);
28 if (fileName.StartsWith ("mono") && fileName.EndsWith (".exe"))
32 if (!File.Exists (Mono))
34 Path.GetDirectoryName (
35 Path.GetDirectoryName (GacPath)),
38 if (!File.Exists (Mono))
40 Path.GetDirectoryName (
41 Path.GetDirectoryName (
42 Path.GetDirectoryName (GacPath))),
43 "mono\\mini\\mono.exe");
45 //if (!File.Exists (Mono))
46 // throw new FileNotFoundException ("Windows mono path not found: " + Mono);
48 CSharpCompiler = Path.Combine (GacPath, "4.5\\mcs.exe");
49 if (!File.Exists (CSharpCompiler))
50 CSharpCompiler = Path.Combine (Path.GetDirectoryName (GacPath), "lib\\build\\mcs.exe");
52 //if (!File.Exists (CSharpCompiler))
53 // throw new FileNotFoundException ("C# compiler not found at " + CSharpCompiler);
55 VBCompiler = Path.Combine (GacPath, "4.5\\vbnc.exe");
56 AssemblyLinker = Path.Combine (GacPath, "4.5\\al.exe");
58 if (!File.Exists (AssemblyLinker)) {
59 AssemblyLinker = Path.Combine (Path.GetDirectoryName (GacPath), "lib\\net_4_x\\al.exe");
60 // if (!File.Exists (AssemblyLinker))
61 // throw new FileNotFoundException ("Windows al path not found: " + AssemblyLinker);
64 Mono = Path.Combine (GacPath, "bin", "mono");
65 if (!File.Exists (Mono))
68 var mscorlibPath = new Uri (typeof (object).Assembly.CodeBase).LocalPath;
69 CSharpCompiler = Path.GetFullPath (Path.Combine (mscorlibPath, "..", "..", "..", "..", "bin", "mcs"));
70 if (!File.Exists (CSharpCompiler))
71 CSharpCompiler = "mcs";
73 VBCompiler = Path.GetFullPath (Path.Combine (mscorlibPath, "..", "..", "..", "..", "bin", "vbnc"));
74 if (!File.Exists (VBCompiler))
77 AssemblyLinker = Path.GetFullPath (Path.Combine (mscorlibPath, "..", "..", "..", "..", "bin", "al"));
78 if (!File.Exists (AssemblyLinker))
79 AssemblyLinker = "al";