Skip to content

Commit a9c2ab8

Browse files
committed
use Rider MSBuild on Windows, when Rider is selected as external editor
1 parent ed0f194 commit a9c2ab8

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using Godot;
5+
using GodotTools.Ides.Rider;
56
using GodotTools.Internals;
67
using Directory = System.IO.Directory;
78
using Environment = System.Environment;
@@ -54,6 +55,12 @@ public static string FindMsBuild()
5455

5556
return msbuildPath;
5657
}
58+
case BuildManager.BuildTool.JetBrainsMsBuild:
59+
var editorPath = (string)editorSettings.GetSetting(RiderPathManager.EditorPathSettingName);
60+
if (!File.Exists(editorPath))
61+
throw new FileNotFoundException($"Cannot find Rider executable. Tried with path: {editorPath}");
62+
var riderDir = new FileInfo(editorPath).Directory.Parent;
63+
return Path.Combine(riderDir.FullName, @"tools\MSBuild\Current\Bin\MSBuild.exe");
5764
default:
5865
throw new IndexOutOfRangeException("Invalid build tool in editor settings");
5966
}

modules/mono/editor/GodotTools/GodotTools/BuildManager.cs

+15-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Threading.Tasks;
55
using GodotTools.Build;
6+
using GodotTools.Ides.Rider;
67
using GodotTools.Internals;
78
using GodotTools.Utils;
89
using static GodotTools.Internals.Globals;
@@ -16,14 +17,16 @@ public static class BuildManager
1617

1718
public const string PropNameMsbuildMono = "MSBuild (Mono)";
1819
public const string PropNameMsbuildVs = "MSBuild (VS Build Tools)";
20+
public const string PropNameMsbuildJetBrains = "MSBuild (JetBrains Rider)";
1921

2022
public const string MsBuildIssuesFileName = "msbuild_issues.csv";
2123
public const string MsBuildLogFileName = "msbuild_log.txt";
2224

2325
public enum BuildTool
2426
{
2527
MsBuildMono,
26-
MsBuildVs
28+
MsBuildVs,
29+
JetBrainsMsBuild
2730
}
2831

2932
private static void RemoveOldIssuesFile(BuildInfo buildInfo)
@@ -181,15 +184,15 @@ public static bool BuildProjectBlocking(string config, IEnumerable<string> godot
181184
var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, config);
182185

183186
// Add Godot defines
184-
string constants = buildTool == BuildTool.MsBuildVs ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";
187+
string constants = buildTool != BuildTool.MsBuildMono ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";
185188

186189
foreach (var godotDefine in godotDefines)
187190
constants += $"GODOT_{godotDefine.ToUpper().Replace("-", "_").Replace(" ", "_").Replace(";", "_")};";
188191

189192
if (Internal.GodotIsRealTDouble())
190193
constants += "GODOT_REAL_T_IS_DOUBLE;";
191194

192-
constants += buildTool == BuildTool.MsBuildVs ? "\"" : "\\\"";
195+
constants += buildTool != BuildTool.MsBuildMono ? "\"" : "\\\"";
193196

194197
buildInfo.CustomProperties.Add(constants);
195198

@@ -245,18 +248,22 @@ public static bool EditorBuildCallback()
245248
public static void Initialize()
246249
{
247250
// Build tool settings
248-
249-
EditorDef("mono/builds/build_tool", OS.IsWindows ? BuildTool.MsBuildVs : BuildTool.MsBuildMono);
250-
251251
var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
252-
252+
var msbuild = BuildTool.MsBuildMono;
253+
if (OS.IsWindows)
254+
msbuild = RiderPathManager.IsRider((string) editorSettings.GetSetting(RiderPathManager.EditorPathSettingName))
255+
? BuildTool.JetBrainsMsBuild
256+
: BuildTool.MsBuildVs;
257+
258+
EditorDef("mono/builds/build_tool", msbuild);
259+
253260
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
254261
{
255262
["type"] = Godot.Variant.Type.Int,
256263
["name"] = "mono/builds/build_tool",
257264
["hint"] = Godot.PropertyHint.Enum,
258265
["hint_string"] = OS.IsWindows ?
259-
$"{PropNameMsbuildMono},{PropNameMsbuildVs}" :
266+
$"{PropNameMsbuildMono},{PropNameMsbuildVs},{PropNameMsbuildJetBrains}" :
260267
$"{PropNameMsbuildMono}"
261268
});
262269

modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs

+13-15
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace GodotTools.Ides.Rider
99
{
1010
public static class RiderPathManager
1111
{
12-
private static readonly string editorPathSettingName = "mono/editor/editor_path_optional";
12+
public static readonly string EditorPathSettingName = "mono/editor/editor_path_optional";
1313

1414
private static string GetRiderPathFromSettings()
1515
{
1616
var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
17-
if (editorSettings.HasSetting(editorPathSettingName))
18-
return (string)editorSettings.GetSetting(editorPathSettingName);
17+
if (editorSettings.HasSetting(EditorPathSettingName))
18+
return (string)editorSettings.GetSetting(EditorPathSettingName);
1919
return null;
2020
}
2121

@@ -25,22 +25,22 @@ public static void Initialize()
2525
var editor = (ExternalEditorId)editorSettings.GetSetting("mono/editor/external_editor");
2626
if (editor == ExternalEditorId.Rider)
2727
{
28-
if (!editorSettings.HasSetting(editorPathSettingName))
28+
if (!editorSettings.HasSetting(EditorPathSettingName))
2929
{
30-
Globals.EditorDef(editorPathSettingName, "Optional");
30+
Globals.EditorDef(EditorPathSettingName, "Optional");
3131
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
3232
{
3333
["type"] = Variant.Type.String,
34-
["name"] = editorPathSettingName,
34+
["name"] = EditorPathSettingName,
3535
["hint"] = PropertyHint.File,
3636
["hint_string"] = ""
3737
});
3838
}
3939

40-
var riderPath = (string)editorSettings.GetSetting(editorPathSettingName);
40+
var riderPath = (string)editorSettings.GetSetting(EditorPathSettingName);
4141
if (IsRiderAndExists(riderPath))
4242
{
43-
Globals.EditorDef(editorPathSettingName, riderPath);
43+
Globals.EditorDef(EditorPathSettingName, riderPath);
4444
return;
4545
}
4646

@@ -50,17 +50,15 @@ public static void Initialize()
5050
return;
5151

5252
var newPath = paths.Last().Path;
53-
Globals.EditorDef(editorPathSettingName, newPath);
54-
editorSettings.SetSetting(editorPathSettingName, newPath);
53+
Globals.EditorDef(EditorPathSettingName, newPath);
54+
editorSettings.SetSetting(EditorPathSettingName, newPath);
5555
}
5656
}
5757

58-
private static bool IsRider(string path)
58+
public static bool IsRider(string path)
5959
{
6060
if (string.IsNullOrEmpty(path))
61-
{
6261
return false;
63-
}
6462

6563
var fileInfo = new FileInfo(path);
6664
var filename = fileInfo.Name.ToLowerInvariant();
@@ -81,8 +79,8 @@ private static string CheckAndUpdatePath(string riderPath)
8179
return null;
8280

8381
var newPath = paths.Last().Path;
84-
editorSettings.SetSetting(editorPathSettingName, newPath);
85-
Globals.EditorDef(editorPathSettingName, newPath);
82+
editorSettings.SetSetting(EditorPathSettingName, newPath);
83+
Globals.EditorDef(EditorPathSettingName, newPath);
8684
return newPath;
8785
}
8886

0 commit comments

Comments
 (0)