diff --git a/src/Libraries/ICSharpCode.Build.Tasks/Project/Gmcs.cs b/src/Libraries/ICSharpCode.Build.Tasks/Project/Gmcs.cs index ddb8a37d8c..509f5ec142 100644 --- a/src/Libraries/ICSharpCode.Build.Tasks/Project/Gmcs.cs +++ b/src/Libraries/ICSharpCode.Build.Tasks/Project/Gmcs.cs @@ -23,7 +23,7 @@ namespace ICSharpCode.Build.Tasks protected override string GenerateFullPathToTool() { - return String.Concat(Environment.GetEnvironmentVariable("ComSpec"), " /c gmcs"); + return MonoToolLocationHelper.GetPathToTool(ToolName); } } } diff --git a/src/Libraries/ICSharpCode.Build.Tasks/Project/ICSharpCode.Build.Tasks.csproj b/src/Libraries/ICSharpCode.Build.Tasks/Project/ICSharpCode.Build.Tasks.csproj index 707cd8bf8f..63250cb8f0 100644 --- a/src/Libraries/ICSharpCode.Build.Tasks/Project/ICSharpCode.Build.Tasks.csproj +++ b/src/Libraries/ICSharpCode.Build.Tasks/Project/ICSharpCode.Build.Tasks.csproj @@ -22,6 +22,7 @@ + @@ -47,6 +48,7 @@ Always + diff --git a/src/Libraries/ICSharpCode.Build.Tasks/Project/Mcs.cs b/src/Libraries/ICSharpCode.Build.Tasks/Project/Mcs.cs index e475826868..f650f63dc5 100644 --- a/src/Libraries/ICSharpCode.Build.Tasks/Project/Mcs.cs +++ b/src/Libraries/ICSharpCode.Build.Tasks/Project/Mcs.cs @@ -23,7 +23,7 @@ namespace ICSharpCode.Build.Tasks protected override string GenerateFullPathToTool() { - return String.Concat(Environment.GetEnvironmentVariable("ComSpec"), " /c mcs"); + return MonoToolLocationHelper.GetPathToTool(ToolName); } } } diff --git a/src/Libraries/ICSharpCode.Build.Tasks/Project/MonoToolLocationHelper.cs b/src/Libraries/ICSharpCode.Build.Tasks/Project/MonoToolLocationHelper.cs new file mode 100644 index 0000000000..593f0a22b5 --- /dev/null +++ b/src/Libraries/ICSharpCode.Build.Tasks/Project/MonoToolLocationHelper.cs @@ -0,0 +1,94 @@ +// +// 2002-2005 AlphaSierraPapa +// GNU General Public License +// +// $Revision$ +// + +using Microsoft.Win32; +using System; +using System.IO; +using System.Security; + +namespace ICSharpCode.Build.Tasks +{ + /// + /// Utility to locate Mono compilers. + /// + public class MonoToolLocationHelper + { + public static readonly string MonoRootKeyName = @"Software\Novell\Mono"; + + static string defaultMonoClr = null; + static string monoSdkPath = null; + + MonoToolLocationHelper() + { + } + + /// + /// Gets the full path, including the filename, of the specified + /// Mono tool. + /// + public static string GetPathToTool(string name) + { + // Look for Mono install path in registry. + + string toolName = Path.ChangeExtension(name, ".bat"); + string sdkPath = MonoSdkPath; + if (sdkPath.Length > 0) { + string toolPath = Path.Combine(sdkPath, String.Concat("bin\\", toolName)); + if (System.IO.File.Exists(toolPath)) { + return String.Concat("\"", toolPath, "\""); + } + } + + // Assume the tool can be executed on the command line. + + string comspec = Environment.GetEnvironmentVariable("ComSpec"); + if (comspec != null) { + return String.Concat(comspec, " /c ", Path.GetFileNameWithoutExtension(name)); + } + + return toolName; + } + + public static string MonoSdkPath { + get { + if (monoSdkPath == null) { + string defaultClr = DefaultMonoClr; + if (defaultClr.Length > 0) { + string keyName = String.Concat(MonoRootKeyName, "\\", defaultClr); + monoSdkPath = ReadRegistryValue(keyName, "SdkInstallRoot"); + } else { + monoSdkPath = String.Empty; + } + } + return monoSdkPath; + } + } + + public static string DefaultMonoClr { + get { + if (defaultMonoClr == null) { + defaultMonoClr = ReadRegistryValue(MonoRootKeyName, "DefaultClr"); + } + return defaultMonoClr; + } + } + + static string ReadRegistryValue(string keyName, string name) + { + try { + RegistryKey key = Registry.LocalMachine.OpenSubKey(keyName); + if (key != null) { + string readValue = (string)key.GetValue(name); + key.Close(); + return readValue; + } + } catch (SecurityException) { } + + return String.Empty; + } + } +}