diff --git a/src/MSBuildLocator/DotNetSdkLocationHelper.cs b/src/MSBuildLocator/DotNetSdkLocationHelper.cs index 3e6e86cc..116ab6cf 100644 --- a/src/MSBuildLocator/DotNetSdkLocationHelper.cs +++ b/src/MSBuildLocator/DotNetSdkLocationHelper.cs @@ -100,16 +100,25 @@ private static IEnumerable GetDotNetBasePaths(string workingDirectory) foreach (string dir in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator)) { string filePath = Path.Combine(dir, exeName); - if (File.Exists(Path.Combine(dir, exeName))) + if (File.Exists(filePath)) { - dotnetPath = filePath; + if (!isWindows) + { + filePath = realpath(filePath) ?? filePath; + if (!File.Exists(filePath)) + { + continue; + } + } + + dotnetPath = Path.GetDirectoryName(filePath); break; } } - if (dotnetPath != null) + if (dotnetPath is null) { - dotnetPath = Path.GetDirectoryName(isWindows ? dotnetPath : realpath(dotnetPath) ?? dotnetPath); + throw new InvalidOperationException("Could not find the dotnet executable. Is it on the PATH?"); } string bestSDK = null;