From 1a944c260918a8d7f6354a8d5a0da5118ce3a04d Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Thu, 14 Dec 2023 16:26:49 +0100 Subject: [PATCH 1/6] Remove the max version limitation & add package tags --- src/MSBuildLocator/DotNetSdkLocationHelper.cs | 10 ---------- src/MSBuildLocator/Microsoft.Build.Locator.csproj | 3 ++- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/MSBuildLocator/DotNetSdkLocationHelper.cs b/src/MSBuildLocator/DotNetSdkLocationHelper.cs index 4d7cc0a..8e7b5ba 100644 --- a/src/MSBuildLocator/DotNetSdkLocationHelper.cs +++ b/src/MSBuildLocator/DotNetSdkLocationHelper.cs @@ -52,16 +52,6 @@ internal static class DotNetSdkLocationHelper return null; } - // Components of the SDK often have dependencies on the runtime they shipped with, including that several tasks that shipped - // in the .NET 5 SDK rely on the .NET 5.0 runtime. Assuming the runtime that shipped with a particular SDK has the same version, - // this ensures that we don't choose an SDK that doesn't work with the runtime of the chosen application. This is not guaranteed - // to always work but should work for now. - if (major > Environment.Version.Major || - (major == Environment.Version.Major && minor > Environment.Version.Minor)) - { - return null; - } - return new VisualStudioInstance( name: ".NET Core SDK", path: dotNetSdkPath, diff --git a/src/MSBuildLocator/Microsoft.Build.Locator.csproj b/src/MSBuildLocator/Microsoft.Build.Locator.csproj index 245fec8..4fba408 100644 --- a/src/MSBuildLocator/Microsoft.Build.Locator.csproj +++ b/src/MSBuildLocator/Microsoft.Build.Locator.csproj @@ -14,7 +14,8 @@ MSBuild Locator Package that assists in locating and using a copy of MSBuild installed as part of Visual Studio 2017 or higher or .NET Core SDK 2.1 or higher. - + msbuildlocator;locator;buildlocator + true 1.6.1 From ec2011b42bcfcc9802099b5c402c9f5e5c4ac6dc Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Thu, 18 Jan 2024 11:37:24 +0100 Subject: [PATCH 2/6] make mechanism for querying all runtime versions optional --- src/MSBuildLocator/DotNetSdkLocationHelper.cs | 16 +++++++++++++--- src/MSBuildLocator/MSBuildLocator.cs | 2 +- .../VisualStudioInstanceQueryOptions.cs | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/MSBuildLocator/DotNetSdkLocationHelper.cs b/src/MSBuildLocator/DotNetSdkLocationHelper.cs index 8e7b5ba..da31f87 100644 --- a/src/MSBuildLocator/DotNetSdkLocationHelper.cs +++ b/src/MSBuildLocator/DotNetSdkLocationHelper.cs @@ -24,7 +24,7 @@ internal static class DotNetSdkLocationHelper private static readonly string ExeName = IsWindows ? "dotnet.exe" : "dotnet"; private static readonly Lazy> s_dotnetPathCandidates = new(() => ResolveDotnetPathCandidates()); - public static VisualStudioInstance? GetInstance(string dotNetSdkPath) + public static VisualStudioInstance? GetInstance(string dotNetSdkPath, bool allowQueryAllRuntimeVersions) { if (string.IsNullOrWhiteSpace(dotNetSdkPath) || !File.Exists(Path.Combine(dotNetSdkPath, "Microsoft.Build.dll"))) { @@ -52,6 +52,16 @@ internal static class DotNetSdkLocationHelper return null; } + // Components of the SDK often have dependencies on the runtime they shipped with, including that several tasks that shipped + // in the .NET 5 SDK rely on the .NET 5.0 runtime. Assuming the runtime that shipped with a particular SDK has the same version, + // this ensures that we don't choose an SDK that doesn't work with the runtime of the chosen application. This is not guaranteed + // to always work but should work for now. + if (major > Environment.Version.Major || (major == Environment.Version.Major && minor > Environment.Version.Minor) + && !allowQueryAllRuntimeVersions) + { + return null; + } + return new VisualStudioInstance( name: ".NET Core SDK", path: dotNetSdkPath, @@ -59,11 +69,11 @@ internal static class DotNetSdkLocationHelper discoveryType: DiscoveryType.DotNetSdk); } - public static IEnumerable GetInstances(string workingDirectory) + public static IEnumerable GetInstances(string workingDirectory, bool allowQueryAllRuntimes) { foreach (var basePath in GetDotNetBasePaths(workingDirectory)) { - var dotnetSdk = GetInstance(basePath); + var dotnetSdk = GetInstance(basePath, allowQueryAllRuntimes); if (dotnetSdk != null) { yield return dotnetSdk; diff --git a/src/MSBuildLocator/MSBuildLocator.cs b/src/MSBuildLocator/MSBuildLocator.cs index cf56c8e..298c326 100644 --- a/src/MSBuildLocator/MSBuildLocator.cs +++ b/src/MSBuildLocator/MSBuildLocator.cs @@ -354,7 +354,7 @@ private static IEnumerable GetInstances(VisualStudioInstan #endif #if NETCOREAPP - foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory)) + foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory, options.AllowQueryAllRuntimeVersions)) yield return dotnetSdk; #endif } diff --git a/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs b/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs index 3c257d8..de073cf 100644 --- a/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs +++ b/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs @@ -33,5 +33,11 @@ public class VisualStudioInstanceQueryOptions /// Working directory to use when querying for instances. Ensure it is the project directory to pick up the right global.json. /// public string WorkingDirectory { get; set; } = Environment.CurrentDirectory; + + /// + /// This variable enables the removal of the existing restriction on querying installed Visual Studio instances + /// with a runtime version lower than or equal to the one in the current environment. + /// + public bool AllowQueryAllRuntimeVersions { get; set; } = Environment.GetEnvironmentVariable("DOTNET_MSBUILD_QUERY_ALL_RUNTIMES") == "1"; } } From f433d52f1f104293c4b512add15554cca3b43715 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Tue, 30 Jan 2024 15:46:56 +0100 Subject: [PATCH 3/6] fix review comment --- src/MSBuildLocator/MSBuildLocator.cs | 8 +++++++- src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs | 6 ------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/MSBuildLocator/MSBuildLocator.cs b/src/MSBuildLocator/MSBuildLocator.cs index 298c326..221a49d 100644 --- a/src/MSBuildLocator/MSBuildLocator.cs +++ b/src/MSBuildLocator/MSBuildLocator.cs @@ -43,6 +43,12 @@ public static class MSBuildLocator /// public static bool IsRegistered => s_registeredHandler != null; + /// + /// This flag enables the removal of the existing restriction on querying installed Visual Studio instances + /// with a runtime version lower than or equal to the one in the current environment. + /// + public static bool AllowQueryAllRuntimeVersions { get; set; } = false; + /// /// Gets a value indicating whether an instance of MSBuild can be registered. /// @@ -354,7 +360,7 @@ private static IEnumerable GetInstances(VisualStudioInstan #endif #if NETCOREAPP - foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory, options.AllowQueryAllRuntimeVersions)) + foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory, AllowQueryAllRuntimeVersions)) yield return dotnetSdk; #endif } diff --git a/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs b/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs index de073cf..3c257d8 100644 --- a/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs +++ b/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs @@ -33,11 +33,5 @@ public class VisualStudioInstanceQueryOptions /// Working directory to use when querying for instances. Ensure it is the project directory to pick up the right global.json. /// public string WorkingDirectory { get; set; } = Environment.CurrentDirectory; - - /// - /// This variable enables the removal of the existing restriction on querying installed Visual Studio instances - /// with a runtime version lower than or equal to the one in the current environment. - /// - public bool AllowQueryAllRuntimeVersions { get; set; } = Environment.GetEnvironmentVariable("DOTNET_MSBUILD_QUERY_ALL_RUNTIMES") == "1"; } } From 55465674a8a9ba5bb413748989118aa100bfae28 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com> Date: Mon, 5 Feb 2024 15:24:29 +0100 Subject: [PATCH 4/6] Fix documentation for the newly added property Co-authored-by: Rainer Sigwald --- src/MSBuildLocator/DotNetSdkLocationHelper.cs | 5 +++-- src/MSBuildLocator/MSBuildLocator.cs | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/MSBuildLocator/DotNetSdkLocationHelper.cs b/src/MSBuildLocator/DotNetSdkLocationHelper.cs index da31f87..f5398ff 100644 --- a/src/MSBuildLocator/DotNetSdkLocationHelper.cs +++ b/src/MSBuildLocator/DotNetSdkLocationHelper.cs @@ -56,8 +56,9 @@ internal static class DotNetSdkLocationHelper // in the .NET 5 SDK rely on the .NET 5.0 runtime. Assuming the runtime that shipped with a particular SDK has the same version, // this ensures that we don't choose an SDK that doesn't work with the runtime of the chosen application. This is not guaranteed // to always work but should work for now. - if (major > Environment.Version.Major || (major == Environment.Version.Major && minor > Environment.Version.Minor) - && !allowQueryAllRuntimeVersions) + if (!allowQueryAllRuntimeVersions && + (major > Environment.Version.Major || + (major == Environment.Version.Major && minor > Environment.Version.Minor))) { return null; } diff --git a/src/MSBuildLocator/MSBuildLocator.cs b/src/MSBuildLocator/MSBuildLocator.cs index 221a49d..9dc9032 100644 --- a/src/MSBuildLocator/MSBuildLocator.cs +++ b/src/MSBuildLocator/MSBuildLocator.cs @@ -44,9 +44,11 @@ public static class MSBuildLocator public static bool IsRegistered => s_registeredHandler != null; /// - /// This flag enables the removal of the existing restriction on querying installed Visual Studio instances - /// with a runtime version lower than or equal to the one in the current environment. + /// Allow discovery of .NET SDK versions that are unlikely to be successfully loaded in the current process. /// + /// + /// Defaults to . Set this to only if your application has special logic to handle loading an incompatible SDK, such as launching a new process with the target SDK's runtime. + /// From a611a2db899b472178729d625b7de27d2ea7e3d6 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com> Date: Mon, 5 Feb 2024 15:49:51 +0100 Subject: [PATCH 5/6] Update version.json to 1.7 --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index ca200cb..1d01149 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "1.6", + "version": "1.7", "assemblyVersion": "1.0.0.0", "publicReleaseRefSpec": [ "^refs/heads/release/.*" From 0294ff64bcf989119ccadb29d507d08c427d2931 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:06:32 +0100 Subject: [PATCH 6/6] Update pull request build for renamed master --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9fd2fef..9c74879 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,7 +5,7 @@ on: branches: [ master ] pull_request: branches: - - master + - main - 'release/**' jobs: