I have several classes that implement IDessertPlugin . They are found in various DLLs that I use MEF to deploy their instances for use as a plug-in in my application.
So what I want to do is display the version number of the DLL from which I loaded the plugins using MEF. One or more plugins are defined in one or more DLLs that I load in my application.
Now I am doing something like this:
var catalog = new AggregateCatalog(); catalog.Catalogs.Add( new DirectoryCatalog(Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().location), "Plugins"))); var container = new CompositionContainer(catalog); container.ComposeParts(this);
And it will be very simple to load plugins from the Plugins subdirectory where my application is running.
Doing something like
catalog.Catalogs.First().Parts.First().GetType().Assembly.FullName
just returns "System.ComponentModel.Composition, Version = 4.0.0.0, ..."
I was hoping to find out that I have version 1.0 of CakePlugins.dll and version 1.1 of IceCreamPlugins.dll. The plugins themselves do not have a version attribute about them - I want to rely on the version of the DLL. Hope this makes sense.
I did not understand what DLLs I use there, so I could call Assembly.GetName().Version on them.
Ideas?
Decision:
So, the solution to my problem was pretty simple after the details were compiled.
My plugin control code has this entry:
[ImportMany(typeof(IDessertPlugin)] private IEnumerable<IDessertPluing> dessertPlugins;
and after the composition of the container components occurred, I could iterate through my plugins as follows:
foreach(var plugin in dessertPlugins) { Console.WriteLine(Assembly.GetAssembly(plugin.GetType()).GetName().Version.ToString()); }
itsmatt
source share