Skip to content

Commit

Permalink
dotnet build: Support resolving assembly references from server folde…
Browse files Browse the repository at this point in the history
…r for plugins
  • Loading branch information
UnknownShadow200 committed Dec 15, 2023
1 parent ee7718b commit c8b174e
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions MCGalaxy/Scripting/Scripting.cs
Expand Up @@ -51,21 +51,38 @@ public static class IScripting

// 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)
{
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;
}

Expand Down

0 comments on commit c8b174e

Please sign in to comment.