我如何获得,有我的MEF的插件每个DLL的版本号?我的、版本号、如何获得、插件

2023-09-03 07:56:53 作者:ǐ逅哙無剘ん

我已经得到了一些该实施 IDessertPlugin 类。这些被发现在我使用MEF旋转起来它们的实例作为插件功能使用在我的应用程序不同的DLL。

所以,我想要做的是显示来自我已经使用MEF加载插件的DLL文件的版本号。一个或多个插件是在一个或多个DLL的定义,我在我的应用程序加载。

现在我做一些事情,像这样:

 变种目录=新AggregateCatalog();
catalog.Catalogs.Add(
   新DirectoryCatalog(Path.Combine(
      Path.GetDirectoryName(Assembly.GetExecutingAssembly()的位置。),插件)));

VAR集装箱=​​新CompositionContainer中(目录);

container.ComposeParts(本);
 

这将加载插件就好从plugins子目录在我的应用程序运行。

做这样的事情

  catalog.Catalogs.First()。部分。第一()的GetType()。Assembly.FullName
 

刚刚返回System.ComponentModel.Composition,版本= 4.0.0.0,...

我一直希望能知道的是,我已经有了1.0版CakePlugins.dll和IceCreamPlugins.dll 1.1版。该插件本身就没有对他们一个版本属性 - 我想依靠DLL的版本。希望这是有道理的。

我还没有想出知道我使用有这样我就可以叫 Assembly.GetName()的DLL文件。版本在他们身上。

想法?

解决方法:

因此​​,解决我的问题是pretty的直截了当的部分已经组成后。

我的插件管理code有像这样的条目:

  [ImportMany(typeof运算(IDessertPlugin)
私人的IEnumerable< IDessertPluing> dessertPlugins;
 
synsoacc.dll

和一旦容器部分组成已经发生了,我可以遍历我的插件,就像这样:

 的foreach(VAR插件在dessertPlugins)
{
   Console.WriteLine(Assembly.GetAssembly(plugin.GetType())的GetName()Version.ToString());
}
 

解决方案

因此​​,解决我的问题是pretty的直截了当的部分已经组成后。我试图挖下到MEF对象本身,而不是考虑保存所有插件,我装的容器。答案是完全忽视了如何将这些插件被加载的事实,只是看实例化对象本身。

我的插件管理code有像这样的条目:

  [ImportMany(typeof运算(IDessertPlugin)
私人的IEnumerable< IDessertPluing> dessertPlugins;
 

和一旦容器部分组成已经发生了,我可以遍历我的插件,就像这样:

 的foreach(VAR插件在dessertPlugins)
{
   Console.WriteLine(Assembly.GetAssembly(plugin.GetType())的GetName()Version.ToString());
}
 

I've got a number of classes which implement IDessertPlugin. These are found in various DLLs which I use MEF to spin up instances of them to use as plug-in functionality in my application.

So what I'm wanting to do is display the version number of the DLLs from which I've loaded plugins using MEF. One or more plugins are defined in one or more DLLs which I load up in my application.

Right now I do something like so:

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 that will load up plugins just fine from the Plugins subdirectory where my application runs.

Doing something like

catalog.Catalogs.First().Parts.First().GetType().Assembly.FullName

just returns "System.ComponentModel.Composition, Version=4.0.0.0, ..."

What I was hoping to be able to know was that I've got Version 1.0 of CakePlugins.dll and Version 1.1 of IceCreamPlugins.dll. The plugins themselves don't have a version attribute about them - I'm wanting to rely upon the version of the DLL. Hope that makes sense.

I haven't figured out to know which DLLs I'm using there so that I can call Assembly.GetName().Version on them.

Ideas?

Solution:

So, the solution to my problem was pretty straightforward after the parts have been composed.

My plugin managing code has an entry like so:

[ImportMany(typeof(IDessertPlugin)]
private IEnumerable<IDessertPluing> dessertPlugins;

and once the container parts composition has taken place, I could iterate through my plug-ins like so:

foreach(var plugin in dessertPlugins)
{
   Console.WriteLine(Assembly.GetAssembly(plugin.GetType()).GetName().Version.ToString());
}

解决方案

So, the solution to my problem was pretty straightforward after the parts have been composed. I was trying to dig down into the MEF objects themselves rather than look into the container that holds all the plug-ins I've loaded. The answer was to totally ignore the fact of how those plug-ins were being loaded and just look at the instantiated objects themselves.

My plugin managing code has an entry like so:

[ImportMany(typeof(IDessertPlugin)]
private IEnumerable<IDessertPluing> dessertPlugins;

and once the container parts composition has taken place, I could iterate through my plug-ins like so:

foreach(var plugin in dessertPlugins)
{
   Console.WriteLine(Assembly.GetAssembly(plugin.GetType()).GetName().Version.ToString());
}