Browse Source

The Mono build task attempts to locate the Mono install path by reading the registry before falling back to its original method of assuming that the Mcs/Gmcs compilers have been added to the Path.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@593 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 21 years ago
parent
commit
a20acba51c
  1. 2
      src/Libraries/ICSharpCode.Build.Tasks/Project/Gmcs.cs
  2. 2
      src/Libraries/ICSharpCode.Build.Tasks/Project/ICSharpCode.Build.Tasks.csproj
  3. 2
      src/Libraries/ICSharpCode.Build.Tasks/Project/Mcs.cs
  4. 94
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoToolLocationHelper.cs

2
src/Libraries/ICSharpCode.Build.Tasks/Project/Gmcs.cs

@ -23,7 +23,7 @@ namespace ICSharpCode.Build.Tasks @@ -23,7 +23,7 @@ namespace ICSharpCode.Build.Tasks
protected override string GenerateFullPathToTool()
{
return String.Concat(Environment.GetEnvironmentVariable("ComSpec"), " /c gmcs");
return MonoToolLocationHelper.GetPathToTool(ToolName);
}
}
}

2
src/Libraries/ICSharpCode.Build.Tasks/Project/ICSharpCode.Build.Tasks.csproj

@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities" />
<Reference Include="Microsoft.Build.Tasks" />
<Reference Include="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
@ -47,6 +48,7 @@ @@ -47,6 +48,7 @@
<None Include="SharpDevelop.Build.Mono.Gmcs.targets">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="MonoToolLocationHelper.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="SharpDevelop.Build.CSharp.targets">

2
src/Libraries/ICSharpCode.Build.Tasks/Project/Mcs.cs

@ -23,7 +23,7 @@ namespace ICSharpCode.Build.Tasks @@ -23,7 +23,7 @@ namespace ICSharpCode.Build.Tasks
protected override string GenerateFullPathToTool()
{
return String.Concat(Environment.GetEnvironmentVariable("ComSpec"), " /c mcs");
return MonoToolLocationHelper.GetPathToTool(ToolName);
}
}
}

94
src/Libraries/ICSharpCode.Build.Tasks/Project/MonoToolLocationHelper.cs

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using Microsoft.Win32;
using System;
using System.IO;
using System.Security;
namespace ICSharpCode.Build.Tasks
{
/// <summary>
/// Utility to locate Mono compilers.
/// </summary>
public class MonoToolLocationHelper
{
public static readonly string MonoRootKeyName = @"Software\Novell\Mono";
static string defaultMonoClr = null;
static string monoSdkPath = null;
MonoToolLocationHelper()
{
}
/// <summary>
/// Gets the full path, including the filename, of the specified
/// Mono tool.
/// </summary>
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;
}
}
}
Loading…
Cancel
Save