Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tests] Find the Microsoft.NET.Sdk (#2307)
Browse files Browse the repository at this point in the history
We don't always install the `2.0.0` version of the .net SDK on macOS.
So we should detect and use the most recent version.  This will mean
that `NetStandardReferenceTest()` might actually start running again.
  • Loading branch information
dellis1972 authored and jonpryor committed Oct 17, 2018
1 parent d53b1fc commit b61941e
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ public string MicrosoftNetSdkDirectory {
get {
string path;
if (IsUnix) {
path = Path.Combine ("/usr", "local", "share", "dotnet", "sdk", "2.0.0", "Sdks", "Microsoft.NET.Sdk");
if (File.Exists (Path.Combine (path, "Sdk", "Sdk.props")))
return path;
return string.Empty;
path = System.IO.Path.Combine ("/usr", "local", "share", "dotnet", "sdk");
return FindLatestDotNetSdk (path);
}
var visualStudioDirectory = GetVisualStudio2017Directory ();
if (!string.IsNullOrEmpty (visualStudioDirectory)) {
Expand Down Expand Up @@ -454,6 +452,26 @@ string QuoteFileName (string fileName)
{
return fileName.Contains (" ") ? $"\"{fileName}\"" : fileName;
}

string FindLatestDotNetSdk (string dotNetPath)
{
if (Directory.Exists (dotNetPath)) {
var directories = from dir in Directory.EnumerateDirectories (dotNetPath)
let version = GetVersionFromDirectory (dir)
where version != null && File.Exists (Path.Combine (dir, "Sdks", "Microsoft.NET.Sdk", "Sdk", "Sdk.props"))
orderby version descending
select Path.Combine (dir, "Sdks", "Microsoft.NET.Sdk");
return directories.FirstOrDefault ();
}
return string.Empty;
}

static Version GetVersionFromDirectory (string dir)
{
Version v;
Version.TryParse (Path.GetFileName (dir), out v);
return v;
}
}
}

0 comments on commit b61941e

Please sign in to comment.