Skip to content

Commit

Permalink
add setting of "DOTNET_HOST_PATH" env variable (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuliiaKovalova committed Aug 25, 2023
1 parent 7aabcd9 commit 4ed1bab
Showing 1 changed file with 10 additions and 0 deletions.
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

0 comments on commit 4ed1bab

Please sign in to comment.