diff --git a/.gitignore b/.gitignore index 6db75f232493..d93aa0542744 100644 --- a/.gitignore +++ b/.gitignore @@ -308,7 +308,7 @@ platform/windows/godot_res.res # Visual Studio 2017 and Visual Studio Code workspace folder /.vs -/.vscode +.vscode/ # Scons progress indicator .scons_node_count diff --git a/modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs b/modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs index 16beacb45c38..05712c8d75d4 100644 --- a/modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs +++ b/modules/mono/editor/GodotSharpTools/Build/BuildSystem.cs @@ -7,6 +7,10 @@ using System.Runtime.InteropServices; using System.Security; using Microsoft.Build.Framework; +using Microsoft.Build.Construction; +using GodotSharpTools.Project; +using System.Net; +using System.Linq; namespace GodotSharpTools.Build { @@ -90,6 +94,8 @@ public bool Build(string loggerAssemblyPath, string loggerOutputDir, string[] cu if (!string.IsNullOrEmpty(frameworkPath)) customPropertiesList.Add("FrameworkPathOverride=" + frameworkPath); + SynchronizeCsproj(); + string compilerArgs = BuildArguments(loggerAssemblyPath, loggerOutputDir, customPropertiesList); ProcessStartInfo startInfo = new ProcessStartInfo(GetMSBuildPath(), compilerArgs); @@ -150,6 +156,8 @@ public bool BuildAsync(string loggerAssemblyPath, string loggerOutputDir, string if (!string.IsNullOrEmpty(frameworkPath)) customPropertiesList.Add("FrameworkPathOverride=" + frameworkPath); + SynchronizeCsproj(); + string compilerArgs = BuildArguments(loggerAssemblyPath, loggerOutputDir, customPropertiesList); ProcessStartInfo startInfo = new ProcessStartInfo(GetMSBuildPath(), compilerArgs); @@ -189,6 +197,42 @@ public bool BuildAsync(string loggerAssemblyPath, string loggerOutputDir, string return true; } + public void SynchronizeCsproj() + { + string projectDirectory = Path.GetDirectoryName(solution); + ProjectRootElement root = ProjectRootElement.Open(solution.Replace(".sln", ".csproj")); + + foreach (var itemGroup in root.ItemGroups) + { + if (itemGroup.Condition.Length != 0) + continue; + + foreach (var item in itemGroup.Items.ToArray()) + { + if (item.ItemType == "Compile") + { + // We need to use WebUtility.UrlDecode because paths in .csproj are URL encoded from some reason + if (!File.Exists(Path.Combine(projectDirectory, WebUtility.UrlDecode(item.Include)))) + { + itemGroup.RemoveChild(item); + } + } + } + } + + foreach (string filePath in Directory.EnumerateFiles(projectDirectory, "*.*", SearchOption.AllDirectories)) + { + if (Path.GetExtension(filePath) == ".cs") + { + string relativePath = filePath.RelativeToPath(projectDirectory); + + root.AddItemChecked("Compile", relativePath); + } + } + + root.Save(); + } + private string BuildArguments(string loggerAssemblyPath, string loggerOutputDir, List customProperties) { string arguments = string.Format(@"""{0}"" /v:normal /t:Build ""/p:{1}"" ""/l:{2},{3};{4}""", diff --git a/modules/mono/editor/GodotSharpTools/Project/ProjectExtensions.cs b/modules/mono/editor/GodotSharpTools/Project/ProjectExtensions.cs index f00ec5a2adcc..4b939b6bfac5 100644 --- a/modules/mono/editor/GodotSharpTools/Project/ProjectExtensions.cs +++ b/modules/mono/editor/GodotSharpTools/Project/ProjectExtensions.cs @@ -32,12 +32,30 @@ public static bool AddItemChecked(this ProjectRootElement root, string itemType, if (!root.HasItem(itemType, include)) { root.AddItem(itemType, include); + return true; } return false; } + public static void RemoveItem(this ProjectRootElement root, string itemType, string include) + { + foreach (var itemGroup in root.ItemGroups) + { + if (itemGroup.Condition.Length != 0) + continue; + + foreach (var item in itemGroup.Items) + { + if (item.ItemType == itemType && item.Include == include) + { + itemGroup.RemoveChild(item); + } + } + } + } + public static Guid GetGuid(this ProjectRootElement root) { foreach (var property in root.Properties) diff --git a/modules/mono/editor/GodotSharpTools/Project/ProjectUtils.cs b/modules/mono/editor/GodotSharpTools/Project/ProjectUtils.cs index 6889ea715f5e..eee911d37215 100644 --- a/modules/mono/editor/GodotSharpTools/Project/ProjectUtils.cs +++ b/modules/mono/editor/GodotSharpTools/Project/ProjectUtils.cs @@ -10,6 +10,7 @@ public static void AddItemToProjectChecked(string projectPath, string itemType, { var dir = Directory.GetParent(projectPath).FullName; var root = ProjectRootElement.Open(projectPath); + if (root.AddItemChecked(itemType, include.RelativeToPath(dir).Replace("/", "\\"))) root.Save(); }