I could completely track what you are actually trying to create, but assuming you want to create a plugin infrastructure where you want to organize plugins in subfolders, for example:
\plugins\foo\foo.dll \plugins\foo\dependency_that_foo_needs.dll \plugins\bar\bar.dll \plugins\bar\dependency_that_bar_needs.dll
The problem that you are facing is that foo.dll does not load its dependency, because the framework does not look in this subdirectory to load the assembly.
Using the latest Managed Extensibility Framework (MEF 2 Preview), you can easily create these things. I suppose you can even do this with an earlier version, however earlier versions forced you to use special attributes in your plugins so that the latest version no longer depends.
So, suppose this is your contract with the plugin:
public interface IPlugin { string Run(); }
To load and run all plugins in \ plugins \ foo \, \ plugins \ bar \, (...), just use this code:
class Program { static void Main(string[] args) { var registration = new RegistrationBuilder(); registration.ForTypesDerivedFrom<IPlugin>().Export().Export<IPlugin>(); var directoryInfo = new DirectoryInfo("./plugins"); var directoryCatalogs = directoryInfo .GetDirectories("*", SearchOption.AllDirectories) .Select(dir => new DirectoryCatalog(dir.FullName, registration)); var aggregateCatalog = new AggregateCatalog(directoryCatalogs); var container = new CompositionContainer(aggregateCatalog); container .GetExportedValues<IPlugin>() .ForEach(plugin => Console.WriteLine(plugin.Run())); Console.ReadLine(); } }
As I said, I could be completely out of the track, but there is a chance that someone is looking for an alternative, this is useful :-)
source share