From 2de756f76117de415eee4cc84b9b27e9c149610c Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 15 May 2024 20:56:16 +0300 Subject: [PATCH] Include configuration specific source files in solution configurations Include only relevant generated source files for selected solution configuration. Fixes Intellisense issues when both ARM64 and Win64 configurations are present in project. --- .../Flax.Build.Tests/Flax.Build.Tests.csproj | 2 +- Source/Tools/Flax.Build/Flax.Build.csproj | 2 +- .../VisualStudio/CSSDKProjectGenerator.cs | 38 +++++++++++++------ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Source/Tools/Flax.Build.Tests/Flax.Build.Tests.csproj b/Source/Tools/Flax.Build.Tests/Flax.Build.Tests.csproj index 873f916c4..0b7036058 100644 --- a/Source/Tools/Flax.Build.Tests/Flax.Build.Tests.csproj +++ b/Source/Tools/Flax.Build.Tests/Flax.Build.Tests.csproj @@ -2,7 +2,7 @@ net8.0 - 11.0 + 12.0 disable annotations true diff --git a/Source/Tools/Flax.Build/Flax.Build.csproj b/Source/Tools/Flax.Build/Flax.Build.csproj index 0270e7f82..d19d931ce 100644 --- a/Source/Tools/Flax.Build/Flax.Build.csproj +++ b/Source/Tools/Flax.Build/Flax.Build.csproj @@ -2,7 +2,7 @@ Exe net8.0 - 11.0 + 12.0 disable annotations false diff --git a/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs index 692c5132f..64c333499 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs @@ -162,7 +162,6 @@ namespace Flax.Build.Projects.VisualStudio csProjectFileContent.AppendLine(""); // Files and folders - csProjectFileContent.AppendLine(" "); var files = new List(); @@ -214,24 +213,41 @@ namespace Flax.Build.Projects.VisualStudio else csProjectFileContent.AppendLine(string.Format(" <{0} Include=\"{1}\" />", fileType, projectPath)); } + csProjectFileContent.AppendLine(" "); if (project.GeneratedSourceFiles != null) { - foreach (var file in project.GeneratedSourceFiles) + foreach (var group in project.GeneratedSourceFiles.GroupBy(x => GetGroupingFromPath(x), y => y)) { - string fileType; - if (file.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)) - fileType = "Compile"; - else - fileType = "None"; + (string targetName, string platform, string arch, string configuration) = group.Key; - var filePath = file.Replace('/', '\\'); - csProjectFileContent.AppendLine(string.Format(" <{0} Visible=\"false\" Include=\"{1}\" />", fileType, filePath)); + var targetConfiguration = project.Targets.First(x => x.Name == targetName).ConfigurationName; + csProjectFileContent.AppendLine($" "); + + foreach (var file in group) + { + string fileType; + if (file.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)) + fileType = "Compile"; + else + fileType = "None"; + + var filePath = file.Replace('/', '\\'); + csProjectFileContent.AppendLine(string.Format(" <{0} Visible=\"false\" Include=\"{1}\" />", fileType, filePath)); + } + + csProjectFileContent.AppendLine(" "); + } + + (string target, string platform, string arch, string configuration) GetGroupingFromPath(string path) + { + ReadOnlySpan span = path.AsSpan(); + Span split = stackalloc Range[path.Count((c) => c == '/' || c == '\\')]; + var _ = MemoryExtensions.SplitAny(path, split, [ '/', '\\' ]); + return (span[split[^5]].ToString(), span[split[^4]].ToString(), span[split[^3]].ToString(), span[split[^2]].ToString()); } } - csProjectFileContent.AppendLine(" "); - // End csProjectFileContent.AppendLine("");