From ced4f3519df279baf2b5754acdd97a1fb909aa12 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Tue, 26 Oct 2021 13:02:56 +0200 Subject: [PATCH] Avoid modifying csproj globbing includes Check if the found globbing include already matches the new path on moving scripts to avoid modifying users' csproj files. --- .../GodotTools.ProjectEditor/ProjectUtils.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs index 742f8c616e9..0a949e5e63f 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs @@ -77,6 +77,19 @@ namespace GodotTools.ProjectEditor if (item == null) return; + // Check if the found item include already matches the new path + var glob = MSBuildGlob.Parse(item.Include); + if (glob.IsMatch(normalizedNewInclude)) + return; + + // Otherwise, if the item include uses globbing it's better to add a new item instead of modifying + if (!string.IsNullOrEmpty(glob.WildcardDirectoryPart) || glob.FilenamePart.Contains("*")) + { + root.AddItem(itemType, normalizedNewInclude.RelativeToPath(dir).Replace("/", "\\")); + root.Save(); + return; + } + item.Include = normalizedNewInclude.RelativeToPath(dir).Replace("/", "\\"); root.Save(); } @@ -315,7 +328,7 @@ namespace GodotTools.ProjectEditor // Godot API References - var apiAssemblies = new[] {ApiAssemblyNames.Core, ApiAssemblyNames.Editor}; + var apiAssemblies = new[] { ApiAssemblyNames.Core, ApiAssemblyNames.Editor }; RemoveElements(root.ItemGroups.SelectMany(g => g.Items) .Where(i => i.ItemType == "Reference" && apiAssemblies.Contains(i.Include)));