The answers above pretty much give you what you need. You can try to download all the dlls that will be connected to your application when the program starts:
// note: your path may differ, this one assumes plugins directory where exe is executed var pluginsDirectory = Path.Combine(AppContext.BaseDirectory, "plugins"); if (Directory.Exists(pluginsDirectory)) { var dllPaths = Directory.GetFiles(pluginsDirectory); if (dllPaths.Count() > 0) { foreach (var dllPath in dllPaths) { Assembly.LoadFrom(Path.Combine("plugins", Path.GetFileName(dllPath))); } } else { // warn about no dlls } } else { // warn about no plugins directory }
How to refer to a DLL and its types:
// if dll file name is My.Plugin.Assembly.ShortName.dll, then reference as follows var pluginAssembly = Assembly.Load("My.Plugin.Assembly.ShortName"); var typesInAssembly = pluginAssembly.GetExportedTypes(); var instanceType = typesInAssembly.FirstOrDefault(t => t.Name == "MyClassName"); var instance = Activator.CreateInstance(instanceType, new object[] { "constructorParam1", "constructorParam2" }); instanceType.InvokeMember("MyMethod", BindingFlags.InvokeMethod, null, instance, new object[] { "methodParam1", "methodParam2" });
You may need to specify your application configuration in order to check the plugins directory. I assume that one child directory of plugins, you can check the list of subdirectory paths.
... <runtime> <assemblyBinding ... <probing privatePath="plugins" /> ...
You need to say something, what type to implement (perhaps a configuration mapping). The interface, as far as I can tell, will simply provide a contract that all plugins will implement to provide the expected method for calling through reflection.
Jeremy ray brown
source share