How do I get the version number of each DLL that has my MEF plugins?

前端 未结 2 1530
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-15 13:01

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 functi

2条回答
  •  没有蜡笔的小新
    2021-02-15 13:33

    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 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());
    }
    

提交回复
热议问题