diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9fd2fef6..9c74879f 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: diff --git a/src/MSBuildLocator/DotNetSdkLocationHelper.cs b/src/MSBuildLocator/DotNetSdkLocationHelper.cs index 4d7cc0a3..f5398ff6 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"))) { @@ -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)) + if (!allowQueryAllRuntimeVersions && + (major > Environment.Version.Major || + (major == Environment.Version.Major && minor > Environment.Version.Minor))) { return null; } @@ -69,11 +70,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 00e959b4..7c7983da 100644 --- a/src/MSBuildLocator/MSBuildLocator.cs +++ b/src/MSBuildLocator/MSBuildLocator.cs @@ -43,6 +43,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. /// @@ -353,7 +361,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, AllowQueryAllRuntimeVersions)) yield return dotnetSdk; #endif } diff --git a/src/MSBuildLocator/Microsoft.Build.Locator.csproj b/src/MSBuildLocator/Microsoft.Build.Locator.csproj index 245fec85..4fba408c 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 diff --git a/version.json b/version.json index ca200cb2..1d011499 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/.*"