Skip to content

Commit

Permalink
Merge pull request #83325 from raulsntos/dotnet/find-latest-sdk
Browse files Browse the repository at this point in the history
C#: Fallback to the latest SDK
  • Loading branch information
akien-mga committed Oct 24, 2023
2 parents 4ec07ff + a186343 commit 398b254
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Linq;
using Microsoft.Build.Construction;
using Microsoft.Build.Locator;

namespace GodotTools.ProjectEditor
{
Expand All @@ -19,15 +21,18 @@ public MSBuildProject(ProjectRootElement root)

public static class ProjectUtils
{
public static void MSBuildLocatorRegisterDefaults(out Version version, out string path)
public static void MSBuildLocatorRegisterLatest(out Version version, out string path)
{
var instance = Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();
var instance = MSBuildLocator.QueryVisualStudioInstances()
.OrderByDescending(x => x.Version)
.First();
MSBuildLocator.RegisterInstance(instance);
version = instance.Version;
path = instance.MSBuildPath;
}

public static void MSBuildLocatorRegisterMSBuildPath(string msbuildPath)
=> Microsoft.Build.Locator.MSBuildLocator.RegisterMSBuildPath(msbuildPath);
=> MSBuildLocator.RegisterMSBuildPath(msbuildPath);

public static MSBuildProject Open(string path)
{
Expand Down
4 changes: 2 additions & 2 deletions modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public override void _EnablePlugin()
var dotNetSdkSearchVersion = Environment.Version;

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

0 comments on commit 398b254

Please sign in to comment.