mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
dotnet build: Support resolving assembly references from server folder for plugins
This commit is contained in:
parent
ee7718b89a
commit
c8b174efde
@ -51,9 +51,14 @@ namespace MCGalaxy.Scripting
|
|||||||
|
|
||||||
// only used for resolving plugin DLLs depending on other plugin DLLs
|
// only used for resolving plugin DLLs depending on other plugin DLLs
|
||||||
static Assembly ResolvePluginAssembly(object sender, ResolveEventArgs args) {
|
static Assembly ResolvePluginAssembly(object sender, ResolveEventArgs args) {
|
||||||
#if !NET_20
|
Assembly requestingAssembly = null;
|
||||||
if (args.RequestingAssembly == null) return null;
|
// This property only exists in .NET framework 4.0 and later
|
||||||
if (!IsPluginDLL(args.RequestingAssembly)) return null;
|
#if !NET_20
|
||||||
|
requestingAssembly = args.RequestingAssembly;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (requestingAssembly == null) return null;
|
||||||
|
if (!IsPluginDLL(requestingAssembly)) return null;
|
||||||
|
|
||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
foreach (Assembly assem in assemblies)
|
foreach (Assembly assem in assemblies)
|
||||||
@ -63,9 +68,21 @@ namespace MCGalaxy.Scripting
|
|||||||
if (args.Name == assem.FullName) return assem;
|
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",
|
Logger.Log(LogType.Warning, "Custom command/plugin [{0}] tried to load [{1}], but it could not be found",
|
||||||
args.RequestingAssembly.FullName, args.Name);
|
requestingAssembly.FullName, args.Name);
|
||||||
#endif
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user