From 9b24d5f2d090b2dc5f21b42175424244a297e7d6 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Sun, 6 Dec 2020 00:56:47 +0100 Subject: [PATCH 1/4] C#: Don't overwrite newer Godot.NET.Sdk patch version in csproj Allow game projects to use a Godot.NET.Sdk with a newer patch version. The major and minor version are still required to be the same. For example: Allow a Godot 3.2.4 C# project to use a hypothetical 3.2.5 version of Godot.NET.Sdk. --- .../GodotTools.ProjectEditor.csproj | 1 + .../ProjectGenerator.cs | 5 ++- .../GodotTools.ProjectEditor/ProjectUtils.cs | 33 ++++++++++++++++--- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/GodotTools.ProjectEditor.csproj b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/GodotTools.ProjectEditor.csproj index cf397793e64a..51651e56f8dd 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/GodotTools.ProjectEditor.csproj +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/GodotTools.ProjectEditor.csproj @@ -7,6 +7,7 @@ + diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs index 7e795ec016d9..0e660aa4f6da 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs @@ -9,8 +9,7 @@ namespace GodotTools.ProjectEditor public static class ProjectGenerator { public const string GodotSdkVersionToUse = "3.2.3"; - - public static string GodotSdkAttrValue => $"Godot.NET.Sdk/{GodotSdkVersionToUse}"; + public const string GodotSdkNameToUse = "Godot.NET.Sdk"; public static ProjectRootElement GenGameProject(string name) { @@ -19,7 +18,7 @@ public static ProjectRootElement GenGameProject(string name) var root = ProjectRootElement.Create(NewProjectFileOptions.None); - root.Sdk = GodotSdkAttrValue; + root.Sdk = $"{GodotSdkNameToUse}/{GodotSdkVersionToUse}"; var mainGroup = root.AddPropertyGroup(); mainGroup.AddProperty("TargetFramework", "net472"); diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs index ba3772c93882..742f8c616e93 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs @@ -4,11 +4,13 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Xml; using System.Xml.Linq; using JetBrains.Annotations; using Microsoft.Build.Construction; using Microsoft.Build.Globbing; +using Semver; namespace GodotTools.ProjectEditor { @@ -189,7 +191,7 @@ public static string[] GetIncludeFiles(string projectPath, string itemType) continue; - string normalizedRemove= item.Remove.NormalizePath(); + string normalizedRemove = item.Remove.NormalizePath(); var glob = MSBuildGlob.Parse(normalizedRemove); @@ -233,7 +235,7 @@ public static void MigrateToProjectSdksStyle(MSBuildProject project, string proj if (!string.IsNullOrEmpty(root.Sdk)) return; - root.Sdk = ProjectGenerator.GodotSdkAttrValue; + root.Sdk = $"{ProjectGenerator.GodotSdkNameToUse}/{ProjectGenerator.GodotSdkVersionToUse}"; root.ToolsVersion = null; root.DefaultTargets = null; @@ -408,11 +410,32 @@ void RemoveNamespace(XElement element) public static void EnsureGodotSdkIsUpToDate(MSBuildProject project) { + string godotSdkAttrValue = $"{ProjectGenerator.GodotSdkNameToUse}/{ProjectGenerator.GodotSdkVersionToUse}"; + var root = project.Root; - string godotSdkAttrValue = ProjectGenerator.GodotSdkAttrValue; + string rootSdk = root.Sdk?.Trim(); - if (!string.IsNullOrEmpty(root.Sdk) && root.Sdk.Trim().Equals(godotSdkAttrValue, StringComparison.OrdinalIgnoreCase)) - return; + if (!string.IsNullOrEmpty(rootSdk)) + { + // Check if the version is already the same. + if (rootSdk.Equals(godotSdkAttrValue, StringComparison.OrdinalIgnoreCase)) + return; + + // We also allow higher versions as long as the major and minor are the same. + var semVerToUse = SemVersion.Parse(ProjectGenerator.GodotSdkVersionToUse); + var godotSdkAttrLaxValueRegex = new Regex($@"^{ProjectGenerator.GodotSdkNameToUse}/(?.*)$"); + + var match = godotSdkAttrLaxValueRegex.Match(rootSdk); + + if (match.Success && + SemVersion.TryParse(match.Groups["ver"].Value, out var semVerDetected) && + semVerDetected.Major == semVerToUse.Major && + semVerDetected.Minor == semVerToUse.Minor && + semVerDetected > semVerToUse) + { + return; + } + } root.Sdk = godotSdkAttrValue; project.HasUnsavedChanges = true; From d639941446ad49de6427da77c3594b3efc038a6b Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Sun, 6 Dec 2020 00:43:40 +0100 Subject: [PATCH 2/4] C#: Fix targeting .NETFramework with Godot.NET.Sdk and .NET 5 Our target was overriding the official one, while not doing its job assuming it was already taken care of... --- modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets index b9c17bad1e2d..fcf9979e58a6 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets @@ -16,7 +16,7 @@ - Date: Sun, 6 Dec 2020 00:52:18 +0100 Subject: [PATCH 3/4] C#: Remove ProjectTypeGuids from Godot.NET.Sdk The property has no effect as the older VS project system doesn't work with Sdk style projects. The presence of the property was preventing Visual Studio for Mac from opening the project if the Godot extension is not installed. --- .../mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props | 2 -- .../mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets | 5 ----- 2 files changed, 7 deletions(-) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props index a965456a0475..c9d90f4810e8 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props @@ -2,8 +2,6 @@ true - - {8F3E2DF0-C35C-4265-82FC-BEA011F4A7ED} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets index fcf9979e58a6..480b5109b1b5 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets @@ -1,11 +1,6 @@ - - true - $(GodotProjectTypeGuid);$(DefaultProjectTypeGuid) - -