dotnet build: Support resolving assembly references from server folder for plugins

This commit is contained in:
UnknownShadow200 2023-12-16 10:43:17 +11:00
parent ee7718b89a
commit c8b174efde

View File

@ -51,9 +51,14 @@ namespace MCGalaxy.Scripting
// only used for resolving plugin DLLs depending on other plugin DLLs
static Assembly ResolvePluginAssembly(object sender, ResolveEventArgs args) {
#if !NET_20
if (args.RequestingAssembly == null) return null;
if (!IsPluginDLL(args.RequestingAssembly)) return null;
Assembly requestingAssembly = null;
// This property only exists in .NET framework 4.0 and later
#if !NET_20
requestingAssembly = args.RequestingAssembly;
#endif
if (requestingAssembly == null) return null;
if (!IsPluginDLL(requestingAssembly)) return null;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assem in assemblies)
@ -61,11 +66,23 @@ namespace MCGalaxy.Scripting
if (!IsPluginDLL(assem)) continue;
if (args.Name == assem.FullName) return assem;
}
}
#if NETSTANDARD
// When there is a .deps.json, dotnet won't automatically always try looking in application's directory to resolve references
// https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/default-probing?source=recommendations#how-are-the-properties-populated
try {
AssemblyName name = new AssemblyName(args.Name);
string path = name.Name + ".dll";
if (File.Exists(path)) return Assembly.LoadFrom(path);
} catch (Exception ex) {
Logger.LogError("Resolving plugin DLL reference", ex);
}
#endif
Logger.Log(LogType.Warning, "Custom command/plugin [{0}] tried to load [{1}], but it could not be found",
args.RequestingAssembly.FullName, args.Name);
#endif
requestingAssembly.FullName, args.Name);
return null;
}