mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Fix Roslyn compiler missing netstandard/System.Runtime references (CS0012)
Add netstandard.dll and System.Runtime.dll as metadata references in both the self-contained and non-self-contained compilation paths. These facade assemblies are required when scripts reference libraries targeting netstandard (e.g. Brigadier.NET), preventing CS0012 errors like: "The type 'Object' is defined in an assembly that is not referenced." Also make the self-contained path resilient to missing facade assemblies by catching FileNotFoundException instead of throwing. Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com> Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/d34fe951-43e5-412d-8d7f-cf9bee3a0d77
This commit is contained in:
parent
54e07cd233
commit
da3b2de2ce
1 changed files with 26 additions and 3 deletions
|
|
@ -129,9 +129,22 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
|||
var assemblyrefs = Assembly.GetEntryAssembly()?.GetReferencedAssemblies().ToList()!;
|
||||
assemblyrefs.Add(new("MinecraftClient"));
|
||||
assemblyrefs.Add(new("System.Private.CoreLib"));
|
||||
// Facade assemblies needed for compiling scripts that reference netstandard libraries (e.g. Brigadier.NET)
|
||||
assemblyrefs.Add(new("netstandard"));
|
||||
assemblyrefs.Add(new("System.Runtime"));
|
||||
|
||||
foreach (var refs in assemblyrefs) {
|
||||
var loadedAssembly = Assembly.Load(refs);
|
||||
Assembly? loadedAssembly;
|
||||
try
|
||||
{
|
||||
loadedAssembly = Assembly.Load(refs);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
// Facade assemblies like netstandard may not be loadable in all environments
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(loadedAssembly.Location)) {
|
||||
// Check if we can access the file from the executable.
|
||||
var reference = files.FirstOrDefault(x =>
|
||||
|
|
@ -145,8 +158,8 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
|||
}
|
||||
|
||||
if (reference is null) {
|
||||
throw new InvalidOperationException(
|
||||
"[Script Error] The executable does not contain a referenced assembly. Assembly name: " + refs.Name);
|
||||
// Facade assemblies may not be in the bundle - skip them silently
|
||||
continue;
|
||||
}
|
||||
|
||||
assemblyStream = reference.AsStream();
|
||||
|
|
@ -163,6 +176,16 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
|||
references.Add(MetadataReference.CreateFromFile(SystemConsole));
|
||||
references.Add(MetadataReference.CreateFromFile(MinecraftClientDll));
|
||||
Assembly.GetEntryAssembly()?.GetReferencedAssemblies().ToList().ForEach(a => references.Add(MetadataReference.CreateFromFile(Assembly.Load(a).Location)));
|
||||
|
||||
// Add facade assemblies needed for Roslyn compilation when referencing
|
||||
// libraries that target netstandard (e.g. Brigadier.NET).
|
||||
var runtimeDir = Path.GetDirectoryName(SystemPrivateCoreLib)!;
|
||||
foreach (var facadeName in new[] { "netstandard.dll", "System.Runtime.dll" })
|
||||
{
|
||||
var facadePath = Path.Combine(runtimeDir, facadeName);
|
||||
if (File.Exists(facadePath))
|
||||
references.Add(MetadataReference.CreateFromFile(facadePath));
|
||||
}
|
||||
}
|
||||
#pragma warning restore IL3000
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue