Skip to content

Commit a186343

Browse files
committed
C#: Fallback to the latest SDK
1 parent a574c02 commit a186343

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Linq;
23
using Microsoft.Build.Construction;
4+
using Microsoft.Build.Locator;
35

46
namespace GodotTools.ProjectEditor
57
{
@@ -19,15 +21,18 @@ public MSBuildProject(ProjectRootElement root)
1921

2022
public static class ProjectUtils
2123
{
22-
public static void MSBuildLocatorRegisterDefaults(out Version version, out string path)
24+
public static void MSBuildLocatorRegisterLatest(out Version version, out string path)
2325
{
24-
var instance = Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();
26+
var instance = MSBuildLocator.QueryVisualStudioInstances()
27+
.OrderByDescending(x => x.Version)
28+
.First();
29+
MSBuildLocator.RegisterInstance(instance);
2530
version = instance.Version;
2631
path = instance.MSBuildPath;
2732
}
2833

2934
public static void MSBuildLocatorRegisterMSBuildPath(string msbuildPath)
30-
=> Microsoft.Build.Locator.MSBuildLocator.RegisterMSBuildPath(msbuildPath);
35+
=> MSBuildLocator.RegisterMSBuildPath(msbuildPath);
3136

3237
public static MSBuildProject Open(string path)
3338
{

modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public override void _EnablePlugin()
456456
var dotNetSdkSearchVersion = Environment.Version;
457457

458458
// First we try to find the .NET Sdk ourselves to make sure we get the
459-
// correct version first (`RegisterDefaults` always picks the latest).
459+
// correct version first, otherwise pick the latest.
460460
if (DotNetFinder.TryFindDotNetSdk(dotNetSdkSearchVersion, out var sdkVersion, out string sdkPath))
461461
{
462462
if (Godot.OS.IsStdOutVerbose())
@@ -468,7 +468,7 @@ public override void _EnablePlugin()
468468
{
469469
try
470470
{
471-
ProjectUtils.MSBuildLocatorRegisterDefaults(out sdkVersion, out sdkPath);
471+
ProjectUtils.MSBuildLocatorRegisterLatest(out sdkVersion, out sdkPath);
472472
if (Godot.OS.IsStdOutVerbose())
473473
Console.WriteLine($"Found .NET Sdk version '{sdkVersion}': {sdkPath}");
474474
}

0 commit comments

Comments
 (0)