From e88a016e8f3ab4c5ff26a40a14b48aa76e507721 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 15 Aug 2023 13:24:01 +0200 Subject: [PATCH 1/4] Bump Microsoft.VisualStudio.Setup.Configuration.Interop (#227) Bumps Microsoft.VisualStudio.Setup.Configuration.Interop from 3.6.2115 to 3.7.2175. --- updated-dependencies: - dependency-name: Microsoft.VisualStudio.Setup.Configuration.Interop dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- src/MSBuildLocator/Microsoft.Build.Locator.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MSBuildLocator/Microsoft.Build.Locator.csproj b/src/MSBuildLocator/Microsoft.Build.Locator.csproj index b7c193ef..bdc05282 100644 --- a/src/MSBuildLocator/Microsoft.Build.Locator.csproj +++ b/src/MSBuildLocator/Microsoft.Build.Locator.csproj @@ -21,7 +21,7 @@ - + From fc92380397478d86fa9f1fda69f1d2058f5809a5 Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Tue, 22 Aug 2023 02:14:54 -0700 Subject: [PATCH 2/4] Respect DOTNET_ROOT (#225) * Respect DOTNET_ROOT * DOTNET_ROOT is a folder. Also, DOTNET_ROOT(x86) * PR Feedback --------- Co-authored-by: Forgind --- src/MSBuildLocator/DotNetSdkLocationHelper.cs | 64 ++++++++++++++----- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/src/MSBuildLocator/DotNetSdkLocationHelper.cs b/src/MSBuildLocator/DotNetSdkLocationHelper.cs index 116ab6cf..12f65aad 100644 --- a/src/MSBuildLocator/DotNetSdkLocationHelper.cs +++ b/src/MSBuildLocator/DotNetSdkLocationHelper.cs @@ -78,6 +78,10 @@ public static IEnumerable GetInstances(string workingDirec } } + /// + /// This native method call determines the actual location of path, including + /// resolving symbolic links. + /// private static string realpath(string path) { IntPtr ptr = NativeMethods.realpath(path, IntPtr.Zero); @@ -86,33 +90,63 @@ private static string realpath(string path) return result; } + private static string FindDotnetFromEnvironmentVariable(string environmentVariable, string exeName) + { + string dotnet_root = Environment.GetEnvironmentVariable(environmentVariable); + if (!string.IsNullOrEmpty(dotnet_root)) + { + string fullPathToDotnetFromRoot = Path.Combine(dotnet_root, exeName); + if (File.Exists(fullPathToDotnetFromRoot)) + { + return realpath(fullPathToDotnetFromRoot) ?? fullPathToDotnetFromRoot; + } + } + + return null; + } + private static IEnumerable GetDotNetBasePaths(string workingDirectory) { string dotnetPath = null; bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); string exeName = isWindows ? "dotnet.exe" : "dotnet"; - // We will generally find the dotnet exe on the path, but on linux, it is often just a 'dotnet' symlink (possibly even to more symlinks) that we have to resolve - // to the real dotnet executable. - // This will work as often as just invoking dotnet from the command line, but we can be more confident in finding a dotnet executable by following - // https://github.com/dotnet/designs/blob/main/accepted/2021/install-location-per-architecture.md - // This can be done using the nethost library. We didn't do this previously, so I did not implement this extension. - foreach (string dir in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator)) + // First check for the DOTNET_ROOT environment variable, as it's often there as with, for example, dotnet format. + if (IntPtr.Size == 4) { - string filePath = Path.Combine(dir, exeName); - if (File.Exists(filePath)) + // 32-bit architecture + dotnetPath ??= FindDotnetFromEnvironmentVariable("DOTNET_ROOT(x86)", exeName); + } + else if (IntPtr.Size == 8) + { + // 64-bit architecture + dotnetPath ??= FindDotnetFromEnvironmentVariable("DOTNET_ROOT", exeName); + } + + if (dotnetPath is null) + { + // We will generally find the dotnet exe on the path, but on linux, it is often just a 'dotnet' symlink (possibly even to more symlinks) that we have to resolve + // to the real dotnet executable. + // This will work as often as just invoking dotnet from the command line, but we can be more confident in finding a dotnet executable by following + // https://github.com/dotnet/designs/blob/main/accepted/2021/install-location-per-architecture.md + // This can be done using the nethost library. We didn't do this previously, so I did not implement this extension. + foreach (string dir in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator)) { - if (!isWindows) + string filePath = Path.Combine(dir, exeName); + if (File.Exists(filePath)) { - filePath = realpath(filePath) ?? filePath; - if (!File.Exists(filePath)) + if (!isWindows) { - continue; + filePath = realpath(filePath) ?? filePath; + if (!File.Exists(filePath)) + { + continue; + } } - } - dotnetPath = Path.GetDirectoryName(filePath); - break; + dotnetPath = dir; + break; + } } } From abdf0ed9ab2d51cd5f6a7abfa31ccc2504cbe65a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:15:16 +0200 Subject: [PATCH 3/4] Bump Microsoft.NET.Test.Sdk from 17.7.0 to 17.7.1 (#228) Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.7.0 to 17.7.1. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](https://github.com/microsoft/vstest/compare/v17.7.0...v17.7.1) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj b/src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj index d16f1656..efc837d5 100644 --- a/src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj +++ b/src/MSBuildLocator.Tests/Microsoft.Build.Locator.Tests.csproj @@ -8,7 +8,7 @@ - + From 6b320c113b2b3a858d01c93ca15d4e429ee41475 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:58:21 +0200 Subject: [PATCH 4/4] upgrade core version to net6.0 (#231) * upgrade framework version + fix issue with path extraction from environment variable * fix review comments --- samples/BuilderApp/BuilderApp.csproj | 2 +- .../Microsoft.Build.Locator.Tests.csproj | 2 +- src/MSBuildLocator/DotNetSdkLocationHelper.cs | 21 ++++++++++++++----- .../Microsoft.Build.Locator.csproj | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) 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