Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update condition for max version limitation & add package tags #265

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/MSBuildLocator/DotNetSdkLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class DotNetSdkLocationHelper
private static readonly string ExeName = IsWindows ? "dotnet.exe" : "dotnet";
private static readonly Lazy<IList<string>> 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")))
{
Expand Down Expand Up @@ -56,8 +56,8 @@ 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 (major > Environment.Version.Major || (major == Environment.Version.Major && minor > Environment.Version.Minor)
&& !allowQueryAllRuntimeVersions)
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved
{
return null;
}
Expand All @@ -69,11 +69,11 @@ internal static class DotNetSdkLocationHelper
discoveryType: DiscoveryType.DotNetSdk);
}

public static IEnumerable<VisualStudioInstance> GetInstances(string workingDirectory)
public static IEnumerable<VisualStudioInstance> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/MSBuildLocator/MSBuildLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private static IEnumerable<VisualStudioInstance> 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
}
Expand Down
3 changes: 2 additions & 1 deletion src/MSBuildLocator/Microsoft.Build.Locator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

<Title>MSBuild Locator</Title>
<Description>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.</Description>

<PackageTags>msbuildlocator;locator;buildlocator</PackageTags>

<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>1.6.1</PackageValidationBaselineVersion>
</PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/MSBuildLocator/VisualStudioInstanceQueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public string WorkingDirectory { get; set; } = Environment.CurrentDirectory;

/// <summary>
/// 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.
/// </summary>
public bool AllowQueryAllRuntimeVersions { get; set; } = Environment.GetEnvironmentVariable("DOTNET_MSBUILD_QUERY_ALL_RUNTIMES") == "1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think given the name "AllRuntimes" this should consider allowing .NET Core Locator to find VS installations, which some folks want--for instance #152.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baronfel is there a good scenario for the inverse--.NET Framework locator finding SDK installations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be part of the bucket of scenarios where the user is almost certainly not going to be able to load the MSBuild, but they might just want to list/shell-invoke/etc the MSBuild? It could be useful, but a) wouldn't be as high of a priority in my mind, and b) would need to be behind whatever 'I promise I know this won't work if I try to in-proc this' flag/gate we've set up here.

YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading