Skip to content

make SdkResolver try to locate the dotnet host closest to the resolved SDK #49772

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

Merged
Merged
Show file tree
Hide file tree
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 @@ -196,9 +196,9 @@ private sealed class CachedState
minimumVSDefinedSDKVersion);
}

string? dotnetExe = dotnetRoot != null ?
Path.Combine(dotnetRoot, Constants.DotNetExe) :
null;
string? dotnetExe =
TryResolveDotnetExeFromSdkResolution(resolverResult)
?? Path.Combine(dotnetRoot, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Constants.DotNetExe : Constants.DotNet);
if (File.Exists(dotnetExe))
{
propertiesToAdd ??= new Dictionary<string, string?>();
Expand Down Expand Up @@ -288,6 +288,25 @@ private sealed class CachedState
return factory.IndicateSuccess(msbuildSdkDir, netcoreSdkVersion, propertiesToAdd, itemsToAdd, warnings);
}

/// <summary>Try to find the dotnet binary from the SDK resolution result upwards</summary>
private static string? TryResolveDotnetExeFromSdkResolution(SdkResolutionResult resolverResult)
{
var expectedFileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Constants.DotNetExe : Constants.DotNet;
var currentDir = resolverResult.ResolvedSdkDirectory;
while (currentDir != null)
{
var dotnetExe = Path.Combine(currentDir, expectedFileName);
if (File.Exists(dotnetExe))
{
return dotnetExe;
}

currentDir = Path.GetDirectoryName(currentDir);
}

return null;
}

private static string? GetMSbuildRuntimeVersion(string sdkDirectory, string dotnetRoot)
{
// 1. Get the runtime version from the MSBuild.runtimeconfig.json file
Expand Down
2 changes: 1 addition & 1 deletion src/Resolvers/Microsoft.DotNet.SdkResolver/VSSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private VSSettings()
}

// Test constructor
public VSSettings(string settingsFilePath, bool disallowPrereleaseByDefault)
public VSSettings(string? settingsFilePath, bool disallowPrereleaseByDefault)
{
_settingsFilePath = settingsFilePath;
_disallowPrereleaseByDefault = disallowPrereleaseByDefault;
Expand Down
Loading
Loading