diff --git a/samples/BuilderApp/BuilderApp.csproj b/samples/BuilderApp/BuilderApp.csproj index f8adc233..9035d7de 100644 --- a/samples/BuilderApp/BuilderApp.csproj +++ b/samples/BuilderApp/BuilderApp.csproj @@ -2,7 +2,7 @@ Exe - net472;netcoreapp3.1;net6.0 + net472;net6.0 false false diff --git a/src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj b/src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj index efc837d5..4114e127 100644 --- a/src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj +++ b/src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj @@ -1,7 +1,7 @@ - net472;netcoreapp3.1 + net472;net6.0 false true ..\MSBuildLocator\key.snk diff --git a/src/MSBuildLocator/DotNetSdkLocationHelper.cs b/src/MSBuildLocator/DotNetSdkLocationHelper.cs index 12f65aad..fa41f87d 100644 --- a/src/MSBuildLocator/DotNetSdkLocationHelper.cs +++ b/src/MSBuildLocator/DotNetSdkLocationHelper.cs @@ -17,6 +17,7 @@ internal static class DotNetSdkLocationHelper private static readonly Regex DotNetBasePathRegex = new Regex("Base Path:(.*)$", RegexOptions.Multiline); private static readonly Regex VersionRegex = new Regex(@"^(\d+)\.(\d+)\.(\d+)", RegexOptions.Multiline); private static readonly Regex SdkRegex = new Regex(@"(\S+) \[(.*?)]$", RegexOptions.Multiline); + private static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); public static VisualStudioInstance GetInstance(string dotNetSdkPath) { @@ -98,7 +99,13 @@ private static string FindDotnetFromEnvironmentVariable(string environmentVariab string fullPathToDotnetFromRoot = Path.Combine(dotnet_root, exeName); if (File.Exists(fullPathToDotnetFromRoot)) { - return realpath(fullPathToDotnetFromRoot) ?? fullPathToDotnetFromRoot; + if (!IsWindows) + { + fullPathToDotnetFromRoot = realpath(fullPathToDotnetFromRoot) ?? fullPathToDotnetFromRoot; + return File.Exists(fullPathToDotnetFromRoot) ? Path.GetDirectoryName(fullPathToDotnetFromRoot) : null; + } + + return dotnet_root; } } @@ -108,8 +115,7 @@ private static string FindDotnetFromEnvironmentVariable(string environmentVariab private static IEnumerable GetDotNetBasePaths(string workingDirectory) { string dotnetPath = null; - bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - string exeName = isWindows ? "dotnet.exe" : "dotnet"; + string exeName = IsWindows ? "dotnet.exe" : "dotnet"; // First check for the DOTNET_ROOT environment variable, as it's often there as with, for example, dotnet format. if (IntPtr.Size == 4) @@ -135,10 +141,15 @@ private static IEnumerable GetDotNetBasePaths(string workingDirectory) string filePath = Path.Combine(dir, exeName); if (File.Exists(filePath)) { - if (!isWindows) + if (!IsWindows) { filePath = realpath(filePath) ?? filePath; - if (!File.Exists(filePath)) + if (File.Exists(filePath)) + { + dotnetPath = Path.GetDirectoryName(filePath); + break; + } + else { continue; } diff --git a/src/MSBuildLocator/Microsoft.Build.Locator.csproj b/src/MSBuildLocator/Microsoft.Build.Locator.csproj index bdc05282..056f7ca5 100644 --- a/src/MSBuildLocator/Microsoft.Build.Locator.csproj +++ b/src/MSBuildLocator/Microsoft.Build.Locator.csproj @@ -2,7 +2,7 @@ Library - net46;netcoreapp3.1 + net46;net6.0 full false