From b874e841471418f2d6f5d359dbc0b994768939ec Mon Sep 17 00:00:00 2001 From: Ivan Shakhov Date: Wed, 11 Mar 2020 17:22:12 +0100 Subject: [PATCH] reorder solution configurations + migration (cherry picked from commit ce01b83c4af6b61febecea68596a0806d8723d10) --- .../DotNetSolution.cs | 22 +++++++++++++++++++ .../GodotTools/GodotTools/CsProjOperations.cs | 12 ---------- .../GodotTools/GodotTools/GodotSharpEditor.cs | 15 ++++++++++--- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs index 76cb249acfa..be57683c1f0 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs @@ -1,6 +1,8 @@ using GodotTools.Core; using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Text.RegularExpressions; namespace GodotTools.ProjectEditor { @@ -118,5 +120,25 @@ EndProject"; const string ProjectPlatformsConfig = @" {{{0}}}.{1}|Any CPU.ActiveCfg = {1}|Any CPU {{{0}}}.{1}|Any CPU.Build.0 = {1}|Any CPU"; + + public static void FixConfigurations(string slnPath) + { + if (!File.Exists(slnPath)) + return; + + var input = File.ReadAllText(slnPath); + var dict = new Dictionary + { + {"Debug|Any CPU", "Tools|Any CPU"}, + {"Release|Any CPU", "ExportDebug|Any CPU"}, + {"Tools|Any CPU", "ExportRelease|Any CPU"} + }; + + var regex = new Regex(string.Join("|",dict.Keys.Select(Regex.Escape))); + var result = regex.Replace(input,m => dict[m.Value]); + + if (result != input) + File.WriteAllText(slnPath, result); + } } } diff --git a/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs b/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs index 9abfda4538a..421729cc110 100644 --- a/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs +++ b/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs @@ -32,18 +32,6 @@ namespace GodotTools ProjectUtils.AddItemToProjectChecked(projectPath, itemType, include); } - public static void FixApiHintPath(string projectPath) - { - try - { - ProjectUtils.FixApiHintPath(projectPath); - } - catch (Exception e) - { - GD.PushError(e.ToString()); - } - } - private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); private static ulong ConvertToTimestamp(this DateTime value) diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs index c31d75b76d4..c748a287662 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs @@ -62,7 +62,7 @@ namespace GodotTools { Guid = guid, PathRelativeToSolution = name + ".csproj", - Configs = new List {"Debug", "Release", "Tools"} + Configs = new List { "Tools", "ExportDebug", "ExportRelease" } }; solution.AddNewProject(name, projectInfo); @@ -437,8 +437,17 @@ namespace GodotTools if (File.Exists(GodotSharpDirs.ProjectSlnPath) && File.Exists(GodotSharpDirs.ProjectCsProjPath)) { - // Make sure the existing project has Api assembly references configured correctly - CsProjOperations.FixApiHintPath(GodotSharpDirs.ProjectCsProjPath); + try + { + // Make sure the existing project has Api assembly references configured correctly + ProjectUtils.FixApiHintPath(GodotSharpDirs.ProjectCsProjPath); + // Make sure SolutionConfigurations are Tool, ExportDebug and ExportRelease + DotNetSolution.FixConfigurations(GodotSharpDirs.ProjectSlnPath); + } + catch (Exception e) + { + GD.PushError(e.ToString()); + } } else {