Skip to content
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
10 changes: 10 additions & 0 deletions src/MSBuildLocator/DotNetSdkLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ private static string ResolveDotnetPath()
throw new InvalidOperationException("Could not find the dotnet executable. Is it set on the DOTNET_ROOT?");
}

SetEnvironmentVariableIfEmpty("DOTNET_HOST_PATH", dotnetPath);

return dotnetPath;
}

Expand Down Expand Up @@ -285,6 +287,14 @@ private static string[] GetAllAvailableSDKs()
return string.IsNullOrEmpty(dotnetPath) ? null : ValidatePath(dotnetPath);
}

private static void SetEnvironmentVariableIfEmpty(string name, string value)
{
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(name)))
{
Environment.SetEnvironmentVariable(name, value);
}
}

private static string? ValidatePath(string dotnetPath)
{
string fullPathToDotnetFromRoot = Path.Combine(dotnetPath, ExeName);
Expand Down