From 6daa2be09c7dafe464b69e2565dbc889aebf6d22 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:23:18 +0100 Subject: [PATCH] Update the place for AllowQueryAllRuntimeVersions (#281) * update the plae for AllowQueryAllRuntimeVersions and bump Microsoft.VisualStudio.Setup.Configuration.Interop version * undo version updates * fix review comments --- src/MSBuildLocator/MSBuildLocator.cs | 11 +++++++---- .../VisualStudioInstanceQueryOptions.cs | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/MSBuildLocator/MSBuildLocator.cs b/src/MSBuildLocator/MSBuildLocator.cs index 7b3a5825..f501f49d 100644 --- a/src/MSBuildLocator/MSBuildLocator.cs +++ b/src/MSBuildLocator/MSBuildLocator.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -12,6 +11,8 @@ #if NETCOREAPP using System.Runtime.Loader; +#else +using System.Diagnostics; #endif namespace Microsoft.Build.Locator @@ -367,14 +368,16 @@ private static IEnumerable GetInstances(VisualStudioInstan if (devConsole != null) yield return devConsole; - #if FEATURE_VISUALSTUDIOSETUP +#if FEATURE_VISUALSTUDIOSETUP foreach (var instance in VisualStudioLocationHelper.GetInstances()) yield return instance; - #endif +#endif #endif #if NETCOREAPP - foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory, AllowQueryAllRuntimeVersions)) + // AllowAllRuntimeVersions was added to VisualStudioInstanceQueryOptions for fulfilling Roslyn's needs. One of the properties will be removed in v2.0. + bool allowAllRuntimeVersions = AllowQueryAllRuntimeVersions || options.AllowAllRuntimeVersions; + foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory, allowAllRuntimeVersions)) yield return dotnetSdk; #endif } diff --git a/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs b/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs index 3c257d85..c3e16604 100644 --- a/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs +++ b/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs @@ -29,6 +29,16 @@ public class VisualStudioInstanceQueryOptions /// public DiscoveryType DiscoveryTypes { get; set; } +#if NETCOREAPP + /// + /// 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. + /// /// Working directory to use when querying for instances. Ensure it is the project directory to pick up the right global.json. ///