How to get the version number of each DLL with my MEF plugins?

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()); } 
+8
c # mef
source share
2 answers

So, the solution to my problem was pretty simple after the details were compiled. I tried to delve into the MEF objects themselves, and not look into the container in which all the loaded plugins are stored. The answer was to completely ignore the fact of loading these plugins and just look at the created objects.

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()); } 
+1
source share

You can get assembly information from various properties of AssemblyVersion , AssemblyFileVersion and AssemblyDescription .

  /// <summary> /// This class provide inforamtion about product version. /// </summary> public class ProductVersion { private readonly FileVersionInfo fileVersionInfo; private readonly AssemblyName assemblyName; private ProductVersion(Type type) { // it done this way to prevent situation // when site has limited permissions to work with assemblies. var assembly = Assembly.GetAssembly(type); fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); assemblyName = new AssemblyName(assembly.FullName); } public string AssemblyFileVersion { get { return fileVersionInfo.FileVersion; } } public string AssemblyVersion { get { return assemblyName.Version.ToString(); } } } 
+2
source share

All Articles