-
Notifications
You must be signed in to change notification settings - Fork 87
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
Only consider sdks from before the runtime #106
Changes from 21 commits
7d57e5c
36ca39d
da34277
1eea571
3b1f0a0
5887126
b6353cb
8069139
9e91f9e
47e602b
60cbc46
f7573bc
afe8a1d
32a6f0b
af73626
ae983d3
ec16d05
cd09d13
75c7f2c
3d2ea08
a4af277
930ae79
aa38ab5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,17 +35,15 @@ public static VisualStudioInstance GetInstance(string dotNetSdkPath) | |
return null; | ||
} | ||
|
||
string versionContent = File.ReadAllText(versionPath); | ||
Match versionMatch = VersionRegex.Match(versionContent); | ||
// Preview versions contain a hyphen after the numeric part of the version. Version.TryParse doesn't accept that. | ||
Match versionMatch = VersionRegex.Match(File.ReadAllText(versionPath)); | ||
|
||
if (!versionMatch.Success) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!int.TryParse(versionMatch.Groups[1].Value, out int major) || | ||
if (!versionMatch.Success || | ||
!int.TryParse(versionMatch.Groups[1].Value, out int major) || | ||
!int.TryParse(versionMatch.Groups[2].Value, out int minor) || | ||
!int.TryParse(versionMatch.Groups[3].Value, out int patch)) | ||
!int.TryParse(versionMatch.Groups[3].Value, out int patch) || | ||
major > Environment.Version.Major || | ||
(major == Environment.Version.Major && minor > Environment.Version.Minor)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definitely needs a comment! Describe all the things you've learned about why we care about the current runtime version relative to the SDK version, and the SDK policy as we currently understand it. |
||
{ | ||
return null; | ||
} | ||
|
@@ -127,6 +125,7 @@ private static IEnumerable<string> GetDotNetBasePaths(string workingDirectory) | |
|
||
var lineSdkIndex = lines.FindIndex(line => line.Contains("SDKs installed")); | ||
|
||
List<string> paths = new List<string>(); | ||
if (lineSdkIndex != -1) | ||
{ | ||
lineSdkIndex++; | ||
|
@@ -144,11 +143,20 @@ private static IEnumerable<string> GetDotNetBasePaths(string workingDirectory) | |
path = Path.Combine(path, version) + Path.DirectorySeparatorChar; | ||
|
||
if (!path.Equals(basePath)) | ||
yield return path; | ||
paths.Add(path); | ||
|
||
lineSdkIndex++; | ||
} | ||
} | ||
|
||
// The paths are sorted in increasing order. We want to return the newest SDKs first, however, | ||
// so iterate over the list in reverse order. If basePath is disqualified because it was later | ||
// than the runtime version, this ensures that RegisterDefaults will return the latest valid | ||
// SDK instead of the earliest installed. | ||
for (int i = paths.Count - 1; i >= 0; i--) | ||
{ | ||
yield return paths[i]; | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ internal static IEnumerable<VisualStudioInstance> QueryVisualStudioInstances( | |
/// <returns>Instance of Visual Studio found and registered.</returns> | ||
public static VisualStudioInstance RegisterDefaults() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to implement #106 (comment) Is that wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. Yes, I now think it's not the right design. We could potentially add another overload that takes a bool to "give me everything, I don't care" but I don't think we should filter in RegisterDefaults and I do think we should present only usable instances in the list by default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted to filtering in DotNetSdkLocationHelper.cs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little resistant to add an overload for "give me everything" without anyone explicitly asking for it. I'm guessing most people who use MSBuildLocator use it for relatively straightforward purposes, and it would make it a little harder to pull in my unit testing PR when that comes along. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would this affect a unit testing PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two reasons: it would add something else I'd probably want to test, and since I'm already planning to add an overload to this, I'd have to split my overload into "give me everything" and "don't give me everything" cases. Not a huge deal, though. |
||
{ | ||
var instance = GetInstances(VisualStudioInstanceQueryOptions.Default).FirstOrDefault(); | ||
VisualStudioInstance instance = GetInstances(VisualStudioInstanceQueryOptions.Default).FirstOrDefault(); | ||
if (instance == null) | ||
{ | ||
var error = "No instances of MSBuild could be detected." + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the original flow here because the failure conditions are much more obvious in separate
if
s:Here all together it's hard to see that there are separate failure cases.