public static Assembly LoadPlugin(string relativePath) { // Navigate up to the solution root string root = Path.GetFullPath(Path.Combine( Path.GetDirectoryName( Path.GetDirectoryName( Path.GetDirectoryName( Path.GetDirectoryName( Path.GetDirectoryName(typeof(Program).Assembly.Location))))))); string pluginLocation = Path.GetFullPath(Path.Combine(root, relativePath.Replace('\\', Path.DirectorySeparatorChar))); Console.WriteLine($"Loading commands from: {pluginLocation}"); PluginLoadContext loadContext = new PluginLoadContext(pluginLocation); return(loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(pluginLocation)))); }
public static void LoadPlugins() { if (!IsDirectoryEmpty()) { string[] allDll = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Plugins"), "*.dll"); //PrintFilesDir(allDll); List <Assembly> pluginsAssembly = new List <Assembly>(); //IEnumerable<ICommand> cmds = new IEnumerable<ICommand>(); foreach (string pahtFile in allDll) { Console.WriteLine($"Loading commands from: {pahtFile}"); PluginLoadContext loadContext = new PluginLoadContext(pahtFile); pluginsAssembly.Add(loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(pahtFile)))); Console.WriteLine("ASSEMBLY: " + loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(pahtFile))) .FullName); } Console.WriteLine("Assemble aggiunto alla liosta"); } }