Properly handle empty solution and project paths in SDK resolver #24333
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #24320
In some cases, MSBuild project evaluations are in-memory and so no path context is passed to the SDK resolver. Additionally, some evaluations in Visual Studio specify an empty string for the solution file path which causes the SDK resolver to throw an
ArgumentExceptionerror when passing that toPath.GetDirectoryName().This change checks for
nulland empty/whitespace values to know that the solution file path shouldn't be used. Additionally, if an in-memory project is being evaluated and there is no project file path to fall back to, theEnvironment.CurrentDirectoryis used instead as a best effort starting directory forglobal.json. This could result in the wrongglobal.jsonbeing used but its more likely that noglobal.jsonwill be found and SDK resolution will work like normal.