From b70284c61b5b968f3818a0bff3ed5dcb98725191 Mon Sep 17 00:00:00 2001 From: Yuliia Kovalova Date: Thu, 22 Feb 2024 10:18:31 +0100 Subject: [PATCH 1/3] update the plae for AllowQueryAllRuntimeVersions and bump Microsoft.VisualStudio.Setup.Configuration.Interop version --- src/MSBuildLocator/MSBuildLocator.cs | 13 +++---------- src/MSBuildLocator/Microsoft.Build.Locator.csproj | 2 +- .../VisualStudioInstanceQueryOptions.cs | 10 ++++++++++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/MSBuildLocator/MSBuildLocator.cs b/src/MSBuildLocator/MSBuildLocator.cs index 7c7983da..7ee63d93 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 @@ -43,14 +44,6 @@ public static class MSBuildLocator /// public static bool IsRegistered => s_registeredHandler != null; - /// - /// 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. - /// /// Gets a value indicating whether an instance of MSBuild can be registered. /// @@ -361,7 +354,7 @@ private static IEnumerable GetInstances(VisualStudioInstan #endif #if NETCOREAPP - foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory, AllowQueryAllRuntimeVersions)) + foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory, options.AllowQueryAllRuntimeVersions)) yield return dotnetSdk; #endif } diff --git a/src/MSBuildLocator/Microsoft.Build.Locator.csproj b/src/MSBuildLocator/Microsoft.Build.Locator.csproj index ba90a98a..7738c029 100644 --- a/src/MSBuildLocator/Microsoft.Build.Locator.csproj +++ b/src/MSBuildLocator/Microsoft.Build.Locator.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs b/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs index 3c257d85..b90e40e7 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. /// From ca50741dbefae60fca50c6098f196831e75cc798 Mon Sep 17 00:00:00 2001 From: Yuliia Kovalova Date: Thu, 22 Feb 2024 10:24:26 +0100 Subject: [PATCH 2/3] undo version updates --- 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 7738c029..ba90a98a 100644 --- a/src/MSBuildLocator/Microsoft.Build.Locator.csproj +++ b/src/MSBuildLocator/Microsoft.Build.Locator.csproj @@ -25,7 +25,7 @@ - + From f38037b227c1135f0d3b411781e9be53602168df Mon Sep 17 00:00:00 2001 From: Yuliia Kovalova Date: Mon, 26 Feb 2024 10:56:31 +0100 Subject: [PATCH 3/3] fix review comments --- src/MSBuildLocator/MSBuildLocator.cs | 16 +++++++++++++--- .../VisualStudioInstanceQueryOptions.cs | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/MSBuildLocator/MSBuildLocator.cs b/src/MSBuildLocator/MSBuildLocator.cs index 7ee63d93..e2cb03a0 100644 --- a/src/MSBuildLocator/MSBuildLocator.cs +++ b/src/MSBuildLocator/MSBuildLocator.cs @@ -44,6 +44,14 @@ public static class MSBuildLocator /// public static bool IsRegistered => s_registeredHandler != null; + /// + /// 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. + /// /// Gets a value indicating whether an instance of MSBuild can be registered. /// @@ -347,14 +355,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, options.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 b90e40e7..c3e16604 100644 --- a/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs +++ b/src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs @@ -36,7 +36,7 @@ public class VisualStudioInstanceQueryOptions /// /// 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. ///