Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tests] Find the Microsoft.NET.Sdk #2307

Merged
merged 1 commit into from
Oct 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}