From 5d9e6b7364846f8229647bbeeea18d490e801a05 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 3 Jul 2023 22:00:23 +0200 Subject: [PATCH] Fix C# building to properly use reference assemblies for .NET 7 --- Source/Editor/Editor.Build.cs | 3 ++- .../Flax.Build/Build/DotNet/Builder.DotNet.cs | 10 ++++---- .../Build/NativeCpp/BuildOptions.cs | 24 ++++++++++++++----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Source/Editor/Editor.Build.cs b/Source/Editor/Editor.Build.cs index 64578570c..2e769f431 100644 --- a/Source/Editor/Editor.Build.cs +++ b/Source/Editor/Editor.Build.cs @@ -37,7 +37,8 @@ public class Editor : EditorModule { base.Setup(options); - options.ScriptingAPI.SystemReferences.Add("System.Private.Xml"); + options.ScriptingAPI.SystemReferences.Add("System.Xml"); + options.ScriptingAPI.SystemReferences.Add("System.Xml.ReaderWriter"); options.ScriptingAPI.SystemReferences.Add("System.Text.RegularExpressions"); options.ScriptingAPI.SystemReferences.Add("System.ComponentModel.TypeConverter"); diff --git a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs index e6a250eb5..454376c61 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs @@ -164,6 +164,8 @@ namespace Flax.Build if (!dotnetSdk.IsValid) throw new Exception("Cannot compile C# without .NET SDK"); string dotnetPath = "dotnet", referenceAnalyzers; + string[] runtimeVersionNameParts = dotnetSdk.RuntimeVersionName.Split('.'); + string runtimeVersionShort = runtimeVersionNameParts[0] + '.' + runtimeVersionNameParts[1]; #else string monoRoot, monoPath; #endif @@ -174,7 +176,7 @@ namespace Flax.Build #if USE_NETCORE dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet.exe"); cscPath = Path.Combine(dotnetSdk.RootPath, @$"sdk\{dotnetSdk.VersionName}\Roslyn\bincore\csc.dll"); - referenceAssemblies = Path.Combine(dotnetSdk.RootPath, @$"shared\Microsoft.NETCore.App\{dotnetSdk.RuntimeVersionName}\"); + referenceAssemblies = Path.Combine(dotnetSdk.RootPath, @$"packs\Microsoft.NETCore.App.Ref\{dotnetSdk.RuntimeVersionName}\ref\net{runtimeVersionShort}\"); referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, @$"packs\Microsoft.NETCore.App.Ref\{dotnetSdk.RuntimeVersionName}\analyzers\dotnet\cs\"); #else monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Windows", "Mono"); @@ -190,7 +192,7 @@ namespace Flax.Build { #if USE_NETCORE cscPath = Path.Combine(dotnetSdk.RootPath, $"sdk/{dotnetSdk.VersionName}/Roslyn/bincore/csc.dll"); - referenceAssemblies = Path.Combine(dotnetSdk.RootPath, $"shared/Microsoft.NETCore.App/{dotnetSdk.RuntimeVersionName}/"); + referenceAssemblies = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/ref/net{runtimeVersionShort}/"); referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/analyzers/dotnet/cs/"); #else monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Linux", "Mono"); @@ -204,7 +206,7 @@ namespace Flax.Build { #if USE_NETCORE cscPath = Path.Combine(dotnetSdk.RootPath, $"sdk/{dotnetSdk.VersionName}/Roslyn/bincore/csc.dll"); - referenceAssemblies = Path.Combine(dotnetSdk.RootPath, $"shared/Microsoft.NETCore.App/{dotnetSdk.RuntimeVersionName}/"); + referenceAssemblies = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/ref/net{runtimeVersionShort}/"); referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/analyzers/dotnet/cs/"); #else monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Mac", "Mono"); @@ -256,6 +258,7 @@ namespace Flax.Build args.Add(buildData.Configuration == TargetConfiguration.Release ? "/optimize+" : "/optimize-"); #else args.Add(buildData.Configuration == TargetConfiguration.Debug ? "/optimize-" : "/optimize+"); + args.Add(string.Format("/reference:\"{0}mscorlib.dll\"", referenceAssemblies)); #endif args.Add(string.Format("/out:\"{0}\"", outputFile)); args.Add(string.Format("/doc:\"{0}\"", outputDocFile)); @@ -263,7 +266,6 @@ namespace Flax.Build args.Add("/define:" + string.Join(";", buildOptions.ScriptingAPI.Defines)); if (buildData.Configuration == TargetConfiguration.Debug) args.Add("/define:DEBUG"); - args.Add(string.Format("/reference:\"{0}mscorlib.dll\"", referenceAssemblies)); foreach (var reference in buildOptions.ScriptingAPI.SystemReferences) args.Add(string.Format("/reference:\"{0}{1}.dll\"", referenceAssemblies, reference)); foreach (var reference in fileReferences) diff --git a/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs b/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs index c2ea81372..ef365d3b7 100644 --- a/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs +++ b/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs @@ -244,6 +244,8 @@ namespace Flax.Build.NativeCpp Defines = new HashSet(), SystemReferences = new HashSet { + "mscorlib", + "netstandard", "Microsoft.CSharp", "System", @@ -258,25 +260,32 @@ namespace Flax.Build.NativeCpp //"System.ComponentModel.TypeConverter", "System.Console", "System.Core", + "System.Diagnostics.StackTrace", "System.Globalization", "System.IO", "System.IO.Compression", "System.IO.FileSystem.Watcher", "System.Linq", "System.Linq.Expressions", + "System.Memory", + "System.Net", "System.Net.Http", "System.Net.Primitives", "System.ObjectModel", - "System.Private.CoreLib", - "System.Private.Uri", - //"System.Private.Xml", + "System.ValueTuple", - "System.Reflection", "System.Runtime", + "System.Runtime.Extensions", + "System.Runtime.Handles", + "System.Runtime.Intrinsics", + "System.Runtime.Numerics", + "System.Runtime.Loader", "System.Runtime.CompilerServices.Unsafe", "System.Runtime.InteropServices", "System.Runtime.InteropServices.RuntimeInformation", - "System.Runtime.Serialization.Formatters", // BinaryFormatter + "System.Runtime.Serialization", + "System.Runtime.Serialization.Formatters", + "System.Security.Cryptography", "System.Security.Cryptography.Algorithms", "System.Security.Cryptography.Primitives", @@ -284,8 +293,11 @@ namespace Flax.Build.NativeCpp "System.Threading.Tasks.Parallel", //"System.Xml", + "System.Threading", + "System.Threading.Thread", + + "System.Reflection", //"System.Reflection.Metadata", - "netstandard", }, SystemAnalyzers = new HashSet {