Fix C# building to properly use reference assemblies for .NET 7

This commit is contained in:
Wojtek Figat
2023-07-03 22:00:23 +02:00
parent 9db3439d0d
commit 5d9e6b7364
3 changed files with 26 additions and 11 deletions

View File

@@ -37,7 +37,8 @@ public class Editor : EditorModule
{ {
base.Setup(options); 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.Text.RegularExpressions");
options.ScriptingAPI.SystemReferences.Add("System.ComponentModel.TypeConverter"); options.ScriptingAPI.SystemReferences.Add("System.ComponentModel.TypeConverter");

View File

@@ -164,6 +164,8 @@ namespace Flax.Build
if (!dotnetSdk.IsValid) if (!dotnetSdk.IsValid)
throw new Exception("Cannot compile C# without .NET SDK"); throw new Exception("Cannot compile C# without .NET SDK");
string dotnetPath = "dotnet", referenceAnalyzers; string dotnetPath = "dotnet", referenceAnalyzers;
string[] runtimeVersionNameParts = dotnetSdk.RuntimeVersionName.Split('.');
string runtimeVersionShort = runtimeVersionNameParts[0] + '.' + runtimeVersionNameParts[1];
#else #else
string monoRoot, monoPath; string monoRoot, monoPath;
#endif #endif
@@ -174,7 +176,7 @@ namespace Flax.Build
#if USE_NETCORE #if USE_NETCORE
dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet.exe"); dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet.exe");
cscPath = Path.Combine(dotnetSdk.RootPath, @$"sdk\{dotnetSdk.VersionName}\Roslyn\bincore\csc.dll"); 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\"); referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, @$"packs\Microsoft.NETCore.App.Ref\{dotnetSdk.RuntimeVersionName}\analyzers\dotnet\cs\");
#else #else
monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Windows", "Mono"); monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Windows", "Mono");
@@ -190,7 +192,7 @@ namespace Flax.Build
{ {
#if USE_NETCORE #if USE_NETCORE
cscPath = Path.Combine(dotnetSdk.RootPath, $"sdk/{dotnetSdk.VersionName}/Roslyn/bincore/csc.dll"); 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/"); referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/analyzers/dotnet/cs/");
#else #else
monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Linux", "Mono"); monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Linux", "Mono");
@@ -204,7 +206,7 @@ namespace Flax.Build
{ {
#if USE_NETCORE #if USE_NETCORE
cscPath = Path.Combine(dotnetSdk.RootPath, $"sdk/{dotnetSdk.VersionName}/Roslyn/bincore/csc.dll"); 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/"); referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/analyzers/dotnet/cs/");
#else #else
monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Mac", "Mono"); 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-"); args.Add(buildData.Configuration == TargetConfiguration.Release ? "/optimize+" : "/optimize-");
#else #else
args.Add(buildData.Configuration == TargetConfiguration.Debug ? "/optimize-" : "/optimize+"); args.Add(buildData.Configuration == TargetConfiguration.Debug ? "/optimize-" : "/optimize+");
args.Add(string.Format("/reference:\"{0}mscorlib.dll\"", referenceAssemblies));
#endif #endif
args.Add(string.Format("/out:\"{0}\"", outputFile)); args.Add(string.Format("/out:\"{0}\"", outputFile));
args.Add(string.Format("/doc:\"{0}\"", outputDocFile)); args.Add(string.Format("/doc:\"{0}\"", outputDocFile));
@@ -263,7 +266,6 @@ namespace Flax.Build
args.Add("/define:" + string.Join(";", buildOptions.ScriptingAPI.Defines)); args.Add("/define:" + string.Join(";", buildOptions.ScriptingAPI.Defines));
if (buildData.Configuration == TargetConfiguration.Debug) if (buildData.Configuration == TargetConfiguration.Debug)
args.Add("/define:DEBUG"); args.Add("/define:DEBUG");
args.Add(string.Format("/reference:\"{0}mscorlib.dll\"", referenceAssemblies));
foreach (var reference in buildOptions.ScriptingAPI.SystemReferences) foreach (var reference in buildOptions.ScriptingAPI.SystemReferences)
args.Add(string.Format("/reference:\"{0}{1}.dll\"", referenceAssemblies, reference)); args.Add(string.Format("/reference:\"{0}{1}.dll\"", referenceAssemblies, reference));
foreach (var reference in fileReferences) foreach (var reference in fileReferences)

View File

@@ -244,6 +244,8 @@ namespace Flax.Build.NativeCpp
Defines = new HashSet<string>(), Defines = new HashSet<string>(),
SystemReferences = new HashSet<string> SystemReferences = new HashSet<string>
{ {
"mscorlib",
"netstandard",
"Microsoft.CSharp", "Microsoft.CSharp",
"System", "System",
@@ -258,25 +260,32 @@ namespace Flax.Build.NativeCpp
//"System.ComponentModel.TypeConverter", //"System.ComponentModel.TypeConverter",
"System.Console", "System.Console",
"System.Core", "System.Core",
"System.Diagnostics.StackTrace",
"System.Globalization", "System.Globalization",
"System.IO", "System.IO",
"System.IO.Compression", "System.IO.Compression",
"System.IO.FileSystem.Watcher", "System.IO.FileSystem.Watcher",
"System.Linq", "System.Linq",
"System.Linq.Expressions", "System.Linq.Expressions",
"System.Memory",
"System.Net",
"System.Net.Http", "System.Net.Http",
"System.Net.Primitives", "System.Net.Primitives",
"System.ObjectModel", "System.ObjectModel",
"System.Private.CoreLib", "System.ValueTuple",
"System.Private.Uri",
//"System.Private.Xml",
"System.Reflection",
"System.Runtime", "System.Runtime",
"System.Runtime.Extensions",
"System.Runtime.Handles",
"System.Runtime.Intrinsics",
"System.Runtime.Numerics",
"System.Runtime.Loader",
"System.Runtime.CompilerServices.Unsafe", "System.Runtime.CompilerServices.Unsafe",
"System.Runtime.InteropServices", "System.Runtime.InteropServices",
"System.Runtime.InteropServices.RuntimeInformation", "System.Runtime.InteropServices.RuntimeInformation",
"System.Runtime.Serialization.Formatters", // BinaryFormatter "System.Runtime.Serialization",
"System.Runtime.Serialization.Formatters",
"System.Security.Cryptography", "System.Security.Cryptography",
"System.Security.Cryptography.Algorithms", "System.Security.Cryptography.Algorithms",
"System.Security.Cryptography.Primitives", "System.Security.Cryptography.Primitives",
@@ -284,8 +293,11 @@ namespace Flax.Build.NativeCpp
"System.Threading.Tasks.Parallel", "System.Threading.Tasks.Parallel",
//"System.Xml", //"System.Xml",
"System.Threading",
"System.Threading.Thread",
"System.Reflection",
//"System.Reflection.Metadata", //"System.Reflection.Metadata",
"netstandard",
}, },
SystemAnalyzers = new HashSet<string> SystemAnalyzers = new HashSet<string>
{ {