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

C#: Fallback to the latest SDK #83325

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
C#: Fallback to the latest SDK
  • Loading branch information
raulsntos committed Oct 14, 2023
commit a186343abd0df588c41a3761ecd224654e70323b
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
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