Skip to content

Conversation

@JoeRobich
Copy link
Member

@JoeRobich JoeRobich commented Mar 19, 2025

Review with whitespace off as the formatter removed trailing whitespace.

The method which finds all SDKs has an early exit which stops it from finding SDKs from more than one dotnet install. This PR removes the early exit and filters the returned instances by their reported version number. This should deduplicate the SDKs.

{
string? bestSdkPath;
string[] allAvailableSdks;
try
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inlined GetDotNetBasePaths

string? bestSDK = GetSdkFromGlobalSettings(workingDirectory);
if (!string.IsNullOrEmpty(bestSDK))
// Returns the list of all available SDKs ordered by ascending version.
static string[] GetAllAvailableSDKs()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method and GetSdkFromGlobalSettings were only referenced from the inlined GetDotNetBasePaths so I made them local functions.

for (int i = dotnetPaths.Length - 1; i >= 0; i--)
{
if (dotnetPaths[i] != bestSDK)
if (rc == 0 && resolvedPaths != null)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous behavior was that we would not throw if resolvedPaths was an empty array.

Copy link
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would work the way I'd expect! @baronfel mentioned a concern about diverging from dotnet.exe's behavior in not using other dotnet.exes, but I would want to better understand his reasoning, as I'd argue that MSBuildLocator is (and always has been) more flexible with respect to which MSBuild it ultimately loads than dotnet.exe is, so I see no reason it shouldn't also be more flexible as far as which it finds. That said, we should still solicit feedback from MSBuild, as I don't actually own this product 🙂

@JoeRobich JoeRobich marked this pull request as ready for review March 25, 2025 20:24
@YuliiaKovalova
Copy link
Contributor

it looks good to me, @rainersigwald do you have any concerns?

Comment on lines +111 to +112
// We want to return the newest SDKs first. Using OfType will remove the null entry added if we found the best SDK.
var instances = versionInstanceMap.Values.OfType<VisualStudioInstance>().OrderByDescending(i => i.Version);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am finding this sort confusing with respect to your comment above about keeping the precedence order. That is just per-version, but you'd prefer the overall results sorted by version?

Can you go into more detail on your use case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to preserve the behavior from this comment:

// We want to return the newest SDKs first, however, so iterate over the list in reverse order.

But you are right. I cannot guarantee this will maintain the precedence ordering.

We intend to use this from the MSBuildWorkspace buildhost where we are looking for an SDK and we don't really care where it comes from. If they have pinned a version then we would like to find it, otherwise we would take the SDK with the highest version from any install location.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense I think. The question I have is whether we should embed the sort here, or push it to the caller's layer. I don't think I have super strong opinions so this is fine.

JoeRobich and others added 2 commits March 28, 2025 13:38
Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be a minor version bump, for adding the feature to request this?

@JoeRobich
Copy link
Member Author

I guess this should be a minor version bump, for adding the feature to request this?

Want me to do that in this PR? or as a follow up?

Copy link

@darikprescott darikprescott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems very logical to provide a mechanism to allow faster delivery of sdks and being able to find them faster.

@YuliiaKovalova
Copy link
Contributor

I guess this should be a minor version bump, for adding the feature to request this?

Want me to do that in this PR? or as a follow up?

I have bumped the version , no worries!
Thank you for the contribution.

@YuliiaKovalova YuliiaKovalova enabled auto-merge (squash) March 31, 2025 10:03
@YuliiaKovalova YuliiaKovalova merged commit 6235ee4 into microsoft:main Mar 31, 2025
2 checks passed
@rainersigwald
Copy link
Member

@darikprescott Note that being able to locate the new SDKs does not do anything to make them more loadable; if you wanted to take advantage of this you'd need a big bag of tricks to find and load a newer runtime to load the newer SDK.

@YuliiaKovalova
Copy link
Contributor

It has been released:https://www.nuget.org/packages/Microsoft.Build.Locator/1.8.1 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants