From 5e6fcc9669edb360d791f0d6f494b60983ee94ee Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Thu, 7 Jul 2022 16:10:29 +0300 Subject: [PATCH] Prepare Flax.Build project for .NET 7 Add .NET SDK project generator and upgrade Flax.Build project files --- .../Flax.Build/Build/Builder.Projects.cs | 6 +- Source/Tools/Flax.Build/Build/Builder.cs | 2 + .../Flax.Build/Build/DotNet/Builder.DotNet.cs | 1 + Source/Tools/Flax.Build/Build/EngineTarget.cs | 1 + .../Flax.Build/Build/Graph/LocalExecutor.cs | 1 + Source/Tools/Flax.Build/Build/Target.cs | 7 +- Source/Tools/Flax.Build/Flax.Build.Build.cs | 2 +- Source/Tools/Flax.Build/Flax.Build.csproj | 1 + .../Platforms/Android/AndroidToolchain.cs | 1 + .../Platforms/Linux/LinuxToolchain.cs | 1 + .../Flax.Build/Platforms/Mac/MacToolchain.cs | 1 + .../Flax.Build/Platforms/Unix/UnixPlatform.cs | 2 +- .../Platforms/Unix/UnixToolchain.cs | 1 + .../Platforms/Windows/WindowsToolchainBase.cs | 1 + Source/Tools/Flax.Build/ProjectInfo.cs | 105 ++++++- .../Flax.Build/Projects/ProjectGenerator.cs | 1 + .../VisualStudio/CSSDKProjectGenerator.cs | 257 ++++++++++++++++++ .../VisualStudio/VisualStudioInstance.cs | 1 + .../VisualStudio/VisualStudioProject.cs | 1 + .../VisualStudioCodeProjectGenerator.cs | 2 +- 20 files changed, 386 insertions(+), 9 deletions(-) create mode 100644 Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs diff --git a/Source/Tools/Flax.Build/Build/Builder.Projects.cs b/Source/Tools/Flax.Build/Build/Builder.Projects.cs index bb645a940..6a7fe0b87 100644 --- a/Source/Tools/Flax.Build/Build/Builder.Projects.cs +++ b/Source/Tools/Flax.Build/Build/Builder.Projects.cs @@ -196,7 +196,7 @@ namespace Flax.Build var workspaceRoot = rootProject.ProjectFolderPath; var projectsRoot = Path.Combine(workspaceRoot, "Cache", "Projects"); var projects = new List(); - var dotNetProjectGenerator = ProjectGenerator.Create(projectFormat, TargetType.DotNet); + var dotNetProjectGenerator = ProjectGenerator.Create(projectFormat, TargetType.DotNetCore); var projectToBinaryModule = new Dictionary>>(); var projectToModulesBuildOptions = new Dictionary>(); Project mainSolutionProject = null; @@ -367,7 +367,7 @@ namespace Flax.Build // Create project description var project = dotNetProjectGenerator.CreateProject(); - project.Type = TargetType.DotNet; + project.Type = TargetType.DotNetCore; project.Name = project.BaseName = binaryModuleName; if (mainSolutionProject != null && projectInfo == rootProject) project.Name += ".CSharp"; // Prevent overlapping name with native code project @@ -480,7 +480,7 @@ namespace Flax.Build using (new ProfileEventScope("CreateProject")) { project = dotNetProjectGenerator.CreateProject(); - project.Type = TargetType.DotNet; + project.Type = TargetType.DotNetCore; project.Name = project.BaseName = rulesProjectName; project.Targets = new[] { target }; project.SearchPaths = new string[0]; diff --git a/Source/Tools/Flax.Build/Build/Builder.cs b/Source/Tools/Flax.Build/Build/Builder.cs index 5139ed621..00c43876e 100644 --- a/Source/Tools/Flax.Build/Build/Builder.cs +++ b/Source/Tools/Flax.Build/Build/Builder.cs @@ -334,6 +334,7 @@ namespace Flax.Build BuildTargetNativeCppBindingsOnly(rules, graph, target, buildContext, platform, architecture, configuration); break; case TargetType.DotNet: + case TargetType.DotNetCore: BuildTargetDotNet(rules, graph, target, platform, configuration); break; default: throw new ArgumentOutOfRangeException(); @@ -354,6 +355,7 @@ namespace Flax.Build BuildTargetNativeCpp(rules, graph, target, buildContext, toolchain, configuration); break; case TargetType.DotNet: + case TargetType.DotNetCore: BuildTargetDotNet(rules, graph, target, toolchain.Platform, configuration); break; default: throw new ArgumentOutOfRangeException(); diff --git a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs index 47402131d..3303a95ea 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using Flax.Build.Graph; using Flax.Deploy; +using Task = Flax.Build.Graph.Task; namespace Flax.Build { diff --git a/Source/Tools/Flax.Build/Build/EngineTarget.cs b/Source/Tools/Flax.Build/Build/EngineTarget.cs index 98c87358f..0e5fee7fe 100644 --- a/Source/Tools/Flax.Build/Build/EngineTarget.cs +++ b/Source/Tools/Flax.Build/Build/EngineTarget.cs @@ -4,6 +4,7 @@ using System; using System.IO; using Flax.Build.Graph; using Flax.Build.NativeCpp; +using Task = Flax.Build.Graph.Task; namespace Flax.Build { diff --git a/Source/Tools/Flax.Build/Build/Graph/LocalExecutor.cs b/Source/Tools/Flax.Build/Build/Graph/LocalExecutor.cs index 20aa2e502..7a5b61e01 100644 --- a/Source/Tools/Flax.Build/Build/Graph/LocalExecutor.cs +++ b/Source/Tools/Flax.Build/Build/Graph/LocalExecutor.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.IO; using System.Threading; using Flax.Build.Graph; +using Task = Flax.Build.Graph.Task; namespace Flax.Build.BuildSystem.Graph { diff --git a/Source/Tools/Flax.Build/Build/Target.cs b/Source/Tools/Flax.Build/Build/Target.cs index d78b6ade0..535217dc3 100644 --- a/Source/Tools/Flax.Build/Build/Target.cs +++ b/Source/Tools/Flax.Build/Build/Target.cs @@ -19,9 +19,14 @@ namespace Flax.Build NativeCpp, /// - /// The C# project. + /// The C# Mono project. /// DotNet, + + /// + /// The C# .NET SDK project. + /// + DotNetCore, } /// diff --git a/Source/Tools/Flax.Build/Flax.Build.Build.cs b/Source/Tools/Flax.Build/Flax.Build.Build.cs index b5d2b8fcd..9d77f4707 100644 --- a/Source/Tools/Flax.Build/Flax.Build.Build.cs +++ b/Source/Tools/Flax.Build/Flax.Build.Build.cs @@ -19,7 +19,7 @@ public class FlaxBuildTarget : Target base.Init(); IsPreBuilt = false; - Type = TargetType.DotNet; + Type = TargetType.DotNetCore; OutputType = TargetOutputType.Library; Platforms = new[] { diff --git a/Source/Tools/Flax.Build/Flax.Build.csproj b/Source/Tools/Flax.Build/Flax.Build.csproj index e91be5b0c..183b5f0a2 100644 --- a/Source/Tools/Flax.Build/Flax.Build.csproj +++ b/Source/Tools/Flax.Build/Flax.Build.csproj @@ -161,6 +161,7 @@ + diff --git a/Source/Tools/Flax.Build/Platforms/Android/AndroidToolchain.cs b/Source/Tools/Flax.Build/Platforms/Android/AndroidToolchain.cs index 2c8016a2a..3d5627c1e 100644 --- a/Source/Tools/Flax.Build/Platforms/Android/AndroidToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Android/AndroidToolchain.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using Flax.Build.Graph; using Flax.Build.NativeCpp; +using Task = Flax.Build.Graph.Task; namespace Flax.Build { diff --git a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs index 2904b89a7..4170651f4 100644 --- a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using Flax.Build.Graph; using Flax.Build.NativeCpp; +using Task = Flax.Build.Graph.Task; namespace Flax.Build.Platforms { diff --git a/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs b/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs index 5c934ad0d..c7cf4ccd8 100644 --- a/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs @@ -5,6 +5,7 @@ using System.IO; using System.Collections.Generic; using Flax.Build.Graph; using Flax.Build.NativeCpp; +using Task = Flax.Build.Graph.Task; namespace Flax.Build { diff --git a/Source/Tools/Flax.Build/Platforms/Unix/UnixPlatform.cs b/Source/Tools/Flax.Build/Platforms/Unix/UnixPlatform.cs index 62180306c..e71dd1947 100644 --- a/Source/Tools/Flax.Build/Platforms/Unix/UnixPlatform.cs +++ b/Source/Tools/Flax.Build/Platforms/Unix/UnixPlatform.cs @@ -54,7 +54,7 @@ namespace Flax.Build.Platforms StartInfo = { FileName = "/bin/sh", - Arguments = string.Format("-c 'which {0}'", name), + ArgumentList = { "-c", $"which {name}" }, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, diff --git a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs index 5418575c6..1fe421470 100644 --- a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs @@ -7,6 +7,7 @@ using System.IO; using System.Text.RegularExpressions; using Flax.Build.Graph; using Flax.Build.NativeCpp; +using Task = Flax.Build.Graph.Task; namespace Flax.Build.Platforms { diff --git a/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs b/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs index 3919fcafa..e6eea8639 100644 --- a/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs +++ b/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs @@ -9,6 +9,7 @@ using System.Xml; using Flax.Build.Graph; using Flax.Build.NativeCpp; using Flax.Build.Projects.VisualStudio; +using Task = Flax.Build.Graph.Task; // ReSharper disable InconsistentNaming diff --git a/Source/Tools/Flax.Build/ProjectInfo.cs b/Source/Tools/Flax.Build/ProjectInfo.cs index 803f8b5dd..50aa94698 100644 --- a/Source/Tools/Flax.Build/ProjectInfo.cs +++ b/Source/Tools/Flax.Build/ProjectInfo.cs @@ -8,6 +8,107 @@ using Newtonsoft.Json; namespace Flax.Build { + public class FlaxVersionConverter : JsonConverter + { + /// + /// Writes the JSON representation of the object. + /// + /// The to write to. + /// The value. + /// The calling serializer. + public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + { + if (value == null) + { + writer.WriteNull(); + } + else if (value is Version) + { + writer.WriteValue(value.ToString()); + } + else + { + throw new JsonSerializationException("Expected Version object value"); + } + } + + /// + /// Reads the JSON representation of the object. + /// + /// The to read from. + /// Type of the object. + /// The existing property value of the JSON that is being converted. + /// The calling serializer. + /// The object value. + public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.Null) + { + return null; + } + else + { + if (reader.TokenType == JsonToken.StartObject) + { + try + { + reader.Read(); + Dictionary values = new Dictionary(); + while (reader.TokenType == JsonToken.PropertyName) + { + var key = reader.Value as string; + reader.Read(); + var val = (long)reader.Value; + reader.Read(); + values.Add(key, (int)val); + } + + int major = 0, minor = 0, build = 0; + values.TryGetValue("Major", out major); + values.TryGetValue("Minor", out minor); + values.TryGetValue("Build", out build); + + Version v = new Version(major, minor, build); + return v; + } + catch (Exception ex) + { + throw new Exception(String.Format("Error parsing version string: {0}", reader.Value), ex); + } + } + else if (reader.TokenType == JsonToken.String) + { + try + { + Version v = new Version((string)reader.Value!); + return v; + } + catch (Exception ex) + { + throw new Exception(String.Format("Error parsing version string: {0}", reader.Value), ex); + } + } + else + { + throw new Exception(String.Format("Unexpected token or value when parsing version. Token: {0}, Value: {1}", reader.TokenType, reader.Value)); + } + } + } + + /// + /// Determines whether this instance can convert the specified object type. + /// + /// Type of the object. + /// + /// true if this instance can convert the specified object type; otherwise, false. + /// + public override bool CanConvert(Type objectType) + { + return objectType == typeof(Version); + } + } + + /// /// Contains information about Flax project. /// @@ -154,7 +255,7 @@ namespace Flax.Build /// public void Save() { - var contents = JsonConvert.SerializeObject(this); + var contents = JsonConvert.SerializeObject(this, new JsonSerializerSettings() { Converters = new[] { new FlaxVersionConverter() } }); File.WriteAllText(ProjectPath, contents); } @@ -180,7 +281,7 @@ namespace Flax.Build // Load Log.Verbose("Loading project file from \"" + path + "\"..."); var contents = File.ReadAllText(path); - var project = JsonConvert.DeserializeObject(contents); + var project = JsonConvert.DeserializeObject(contents, new JsonSerializerSettings() { Converters = new[] { new FlaxVersionConverter() } }); project.ProjectPath = path; project.ProjectFolderPath = Path.GetDirectoryName(path); diff --git a/Source/Tools/Flax.Build/Projects/ProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/ProjectGenerator.cs index cb0e5311e..a9fb2b309 100644 --- a/Source/Tools/Flax.Build/Projects/ProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/ProjectGenerator.cs @@ -135,6 +135,7 @@ namespace Flax.Build.Projects { case TargetType.NativeCpp: return new VCProjectGenerator(vsVersion); case TargetType.DotNet: return new CSProjectGenerator(vsVersion); + case TargetType.DotNetCore: return new CSSDKProjectGenerator(vsVersion); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } } diff --git a/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs new file mode 100644 index 000000000..e4819916a --- /dev/null +++ b/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs @@ -0,0 +1,257 @@ +// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace Flax.Build.Projects.VisualStudio +{ + /// + /// The Visual Studio project generator for C# projects (.NET SDK .csproj). + /// + /// + public class CSSDKProjectGenerator : VisualStudioProjectGenerator + { + /// + public CSSDKProjectGenerator(VisualStudioVersion version) : base(version) + { + } + + /// + public override string ProjectFileExtension => "csproj"; + + /// + public override TargetType? Type => TargetType.DotNetCore; + + /// + public override void GenerateProject(Project project) + { + var csProjectFileContent = new StringBuilder(); + + var vsProject = (VisualStudioProject)project; + var projectFileToolVersion = ProjectFileToolVersion; + var projectDirectory = Path.GetDirectoryName(project.Path); + var defaultTarget = project.Targets[0]; + foreach (var target in project.Targets) + { + // Pick the Editor-related target + if (target.IsEditor) + { + defaultTarget = target; + break; + } + } + var defaultConfiguration = TargetConfiguration.Debug; + var defaultArchitecture = TargetArchitecture.AnyCPU; + var projectTypes = ProjectTypeGuids.ToOption(ProjectTypeGuids.WindowsCSharp); + if (vsProject.CSharp.UseFlaxVS && VisualStudioInstance.HasFlaxVS) + projectTypes = ProjectTypeGuids.ToOption(ProjectTypeGuids.FlaxVS) + ';' + projectTypes; + + // Header + csProjectFileContent.AppendLine(""); + csProjectFileContent.AppendLine(""); + + //csProjectFileContent.AppendLine(string.Format("", projectFileToolVersion)); + //csProjectFileContent.AppendLine(" "); + + // Properties + + csProjectFileContent.AppendLine(" "); + + switch (project.OutputType ?? defaultTarget.OutputType) + { + case TargetOutputType.Executable: + csProjectFileContent.AppendLine(" Exe"); + break; + case TargetOutputType.Library: + csProjectFileContent.AppendLine(" Library"); + break; + default: throw new ArgumentOutOfRangeException(); + } + + var baseConfiguration = project.Configurations.First(); + var baseOutputDir = Utilities.MakePathRelativeTo(project.CSharp.OutputPath ?? baseConfiguration.TargetBuildOptions.OutputFolder, projectDirectory); + var baseIntermediateOutputPath = Utilities.MakePathRelativeTo(project.CSharp.IntermediateOutputPath ?? Path.Combine(baseConfiguration.TargetBuildOptions.IntermediateFolder, "CSharp"), projectDirectory); + var baseConfigurations = project.Configurations.Select(x => x.Name.Split('|')[0]).Distinct().ToArray(); + + csProjectFileContent.AppendLine(" net7.0"); + csProjectFileContent.AppendLine(" enable"); + csProjectFileContent.AppendLine(" disable"); + csProjectFileContent.AppendLine(string.Format(" {0}", string.Join(";", baseConfigurations))); + csProjectFileContent.AppendLine(" false"); // ? + csProjectFileContent.AppendLine(" true"); // Needed for Hostfxr + csProjectFileContent.AppendLine(" true"); // ? + csProjectFileContent.AppendLine(" false"); // Prevents outputting the file under net7.0 subdirectory + csProjectFileContent.AppendLine(" $(MSBuildProjectName).CSharp"); // For backwards compatibility, keep the filename same + csProjectFileContent.AppendLine(" false"); // Prevents AssemblyInfo.cs generation (causes duplicate attributes) + csProjectFileContent.AppendLine(" false"); + csProjectFileContent.AppendLine(string.Format(" {0}", baseOutputDir)); // This needs to be set here to fix errors in VS + csProjectFileContent.AppendLine(string.Format(" {0}", baseIntermediateOutputPath)); // This needs to be set here to fix errors in VS + + csProjectFileContent.AppendLine(" "); + csProjectFileContent.AppendLine(""); + + // Default configuration + { + var configuration = project.Configurations.First(); + foreach (var e in project.Configurations) + { + if (e.Configuration == defaultConfiguration && e.Target == defaultTarget && e.Platform == Platform.BuildTargetPlatform) + { + configuration = e; + break; + } + } + var defines = string.Join(";", project.Defines); + if (configuration.TargetBuildOptions.ScriptingAPI.Defines.Count != 0) + { + if (defines.Length != 0) + defines += ";"; + defines += string.Join(";", configuration.TargetBuildOptions.ScriptingAPI.Defines); + } + var outputPath = Utilities.MakePathRelativeTo(project.CSharp.OutputPath ?? configuration.TargetBuildOptions.OutputFolder, projectDirectory); + var intermediateOutputPath = Utilities.MakePathRelativeTo(project.CSharp.IntermediateOutputPath ?? Path.Combine(configuration.TargetBuildOptions.IntermediateFolder, "CSharp"), projectDirectory); + + csProjectFileContent.AppendLine(string.Format(" ", defaultConfiguration, defaultArchitecture)); + csProjectFileContent.AppendLine(" true"); + csProjectFileContent.AppendLine(" portable"); + csProjectFileContent.AppendLine(string.Format(" {0}", defaultConfiguration == TargetConfiguration.Debug ? "false" : "true")); + csProjectFileContent.AppendLine(string.Format(" {0}\\", outputPath)); + csProjectFileContent.AppendLine(string.Format(" {0}\\", intermediateOutputPath)); + csProjectFileContent.AppendLine(string.Format(" {0}\\", intermediateOutputPath)); + csProjectFileContent.AppendLine(string.Format(" {0}", defines)); + csProjectFileContent.AppendLine(" prompt"); + csProjectFileContent.AppendLine(" 4"); + csProjectFileContent.AppendLine(" true"); + if (configuration.TargetBuildOptions.ScriptingAPI.IgnoreMissingDocumentationWarnings) + csProjectFileContent.AppendLine(" 1591"); + csProjectFileContent.AppendLine(string.Format(" {0}\\{1}.CSharp.xml", outputPath, project.Name)); + csProjectFileContent.AppendLine(" true"); + csProjectFileContent.AppendLine(" "); + } + + // Configurations + foreach (var configuration in project.Configurations) + { + var defines = string.Join(";", project.Defines); + if (configuration.TargetBuildOptions.ScriptingAPI.Defines.Count != 0) + { + if (defines.Length != 0) + defines += ";"; + defines += string.Join(";", configuration.TargetBuildOptions.ScriptingAPI.Defines); + } + var outputPath = Utilities.MakePathRelativeTo(project.CSharp.OutputPath ?? configuration.TargetBuildOptions.OutputFolder, projectDirectory); + var intermediateOutputPath = Utilities.MakePathRelativeTo(project.CSharp.IntermediateOutputPath ?? Path.Combine(configuration.TargetBuildOptions.IntermediateFolder, "CSharp"), projectDirectory); + + csProjectFileContent.AppendLine(string.Format(" ", configuration.Name, configuration.Name.Replace(configuration.ArchitectureName, "AnyCPU"))); + csProjectFileContent.AppendLine(" true"); + csProjectFileContent.AppendLine(" portable"); + csProjectFileContent.AppendLine(string.Format(" {0}", configuration.Configuration == TargetConfiguration.Debug ? "false" : "true")); + csProjectFileContent.AppendLine(string.Format(" {0}\\", outputPath)); + csProjectFileContent.AppendLine(string.Format(" {0}\\", intermediateOutputPath)); + csProjectFileContent.AppendLine(string.Format(" {0}\\", intermediateOutputPath)); + csProjectFileContent.AppendLine(string.Format(" {0}", defines)); + csProjectFileContent.AppendLine(" prompt"); + csProjectFileContent.AppendLine(" 4"); + csProjectFileContent.AppendLine(" true"); + if (configuration.TargetBuildOptions.ScriptingAPI.IgnoreMissingDocumentationWarnings) + csProjectFileContent.AppendLine(" 1591"); + csProjectFileContent.AppendLine(string.Format(" {0}\\{1}.CSharp.xml", outputPath, project.Name)); + csProjectFileContent.AppendLine(" true"); + csProjectFileContent.AppendLine(" "); + } + + // Nuget Package References + csProjectFileContent.AppendLine(" "); + csProjectFileContent.AppendLine(" "); + csProjectFileContent.AppendLine(" "); + csProjectFileContent.AppendLine(" "); + csProjectFileContent.AppendLine(" "); + csProjectFileContent.AppendLine(" "); + csProjectFileContent.AppendLine(" "); + csProjectFileContent.AppendLine(" "); + + // References + + csProjectFileContent.AppendLine(" "); + + foreach (var reference in project.CSharp.SystemReferences) + { + csProjectFileContent.AppendLine(string.Format(" ", reference)); + } + + foreach (var reference in project.CSharp.FileReferences) + { + csProjectFileContent.AppendLine(string.Format(" ", Path.GetFileNameWithoutExtension(reference))); + csProjectFileContent.AppendLine(string.Format(" {0}", Utilities.MakePathRelativeTo(reference, projectDirectory))); + csProjectFileContent.AppendLine(" "); + } + + foreach (var dependency in project.Dependencies) + { + csProjectFileContent.AppendLine(string.Format(" ", Utilities.MakePathRelativeTo(dependency.Path, projectDirectory))); + csProjectFileContent.AppendLine(string.Format(" {0}", ((VisualStudioProject)dependency).ProjectGuid.ToString("B").ToUpperInvariant())); + csProjectFileContent.AppendLine(string.Format(" {0}", dependency.Name)); + csProjectFileContent.AppendLine(" "); + } + + csProjectFileContent.AppendLine(" "); + + // Files and folders + + csProjectFileContent.AppendLine(" "); + + var files = new List(); + if (project.SourceFiles != null) + files.AddRange(project.SourceFiles); + if (project.SourceDirectories != null) + { + foreach (var folder in project.SourceDirectories) + { + files.AddRange(Directory.GetFiles(folder, "*", SearchOption.AllDirectories)); + } + } + + foreach (var file in files) + { + string fileType; + if (file.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)) + fileType = "Compile"; + else + fileType = "None"; + + var projectPath = Utilities.MakePathRelativeTo(file, projectDirectory); + csProjectFileContent.AppendLine(string.Format(" <{0} Include=\"{1}\" />", fileType, projectPath)); + } + + if (project.GeneratedSourceFiles != null) + { + foreach (var file in project.GeneratedSourceFiles) + { + string fileType; + if (file.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)) + fileType = "Compile"; + else + fileType = "None"; + + csProjectFileContent.AppendLine(string.Format(" <{0} Visible=\"false\" Include=\"{1}\" />", fileType, file)); + } + } + + csProjectFileContent.AppendLine(" "); + + // End + + //csProjectFileContent.AppendLine(" "); + csProjectFileContent.AppendLine(""); + + if (defaultTarget.CustomExternalProjectFilePath == null) + { + // Save the files + Utilities.WriteFileIfChanged(project.Path, csProjectFileContent.ToString()); + } + } + } +} diff --git a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioInstance.cs b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioInstance.cs index b719fc17f..28e11c124 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioInstance.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioInstance.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using Flax.Build.Platforms; using Microsoft.VisualStudio.Setup.Configuration; +using Task = Flax.Build.Graph.Task; namespace Flax.Build.Projects.VisualStudio { diff --git a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProject.cs b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProject.cs index 816155f75..f546d71a4 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProject.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProject.cs @@ -31,6 +31,7 @@ namespace Flax.Build.Projects.VisualStudio { case TargetType.NativeCpp: return VisualStudioProjectGenerator.ProjectTypeGuids.WindowsVisualCpp; case TargetType.DotNet: return VisualStudioProjectGenerator.ProjectTypeGuids.WindowsCSharp; + case TargetType.DotNetCore: return VisualStudioProjectGenerator.ProjectTypeGuids.WindowsCSharp; default: throw new ArgumentOutOfRangeException(); } } diff --git a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs index 930915a79..c97731007 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs @@ -428,7 +428,7 @@ namespace Flax.Build.Projects.VisualStudioCode } } // C# project - else if (project.Type == TargetType.DotNet) + else if (project.Type == TargetType.DotNet || project.Type == TargetType.DotNetCore) { foreach (var configuration in project.Configurations) {