Skip to content
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

Enable building with a dotnet not on PATH #69186

Merged
merged 3 commits into from
Jul 24, 2023
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
16 changes: 10 additions & 6 deletions src/Compilers/Shared/RuntimeHostInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,20 @@ internal static (string processFilePath, string commandLineArguments, string too

internal static bool IsCoreClrRuntime => true;

private const string DotNetHostPathEnvironmentName = "DOTNET_HOST_PATH";

/// <summary>
/// Get the path to the dotnet executable. In the case the host did not provide this information
/// in the environment this will return simply "dotnet".
/// Get the path to the dotnet executable. In the case the .NET SDK did not provide this information
/// in the environment this tries to find "dotnet" on the PATH. In the case it is not found,
/// this will return simply "dotnet".
/// </summary>
/// <remarks>
/// See the following issue for rationale why only %PATH% is considered
/// https://github.com/dotnet/runtime/issues/88754
/// </remarks>
internal static string GetDotNetPathOrDefault()
{
if (Environment.GetEnvironmentVariable(DotNetHostPathEnvironmentName) is string pathToDotNet)
{
return pathToDotNet;
}

var (fileName, sep) = PlatformInformation.IsWindows
? ("dotnet.exe", ';')
: ("dotnet", ':');
Expand Down