mardi 17 août 2021

Return the path to calling assembly from referenced one

I'm developing plugin based application using MEF2 - System.Composition.

I have library named Core.dll. It contains interfaces, classes and extensions for communication between shell and plugins. Library is targeting .NET Standard,

My plugin Plugin1.dll referenced to Core.dll

Plugins are hosted in Shell.exe (plugins are dicovered by below attribute)

My plugin class is marked with attribute PluginDescription and is located in assembly file Plugin1.dll

    [PluginDescription(
        "Sample plugin",
        "pack://application:,,,/PluginSample;component/plug.png", 
        "test", 
        "test", 
        "test")]
    public class Sample : IPlugin
    {
    }

PluginDescription class looks like this and is located in assembly file Core.dll

    [MetadataAttribute]
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public sealed class PluginDescriptionAttribute : ExportAttribute, IPluginDescription
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="label"></param>
        /// <param name="version"></param>
        /// <param name="author"></param>
        /// <param name="description"></param>
        public PluginDescriptionAttribute(string label, string icon, string version, string author, string description)
            : base(typeof(IPlugin))
        {
            Label = label;
            Icon = icon;
            Version = version;
            Author = author;
            Description = description;
    }

I want to call in constructor class PluginDescriptionAttribute code that will return path to assembly file (Plugin1.dll) that call this constructor.

I tried, but its seeme never return location of Plugin1.dll

StackFrame[] frames = new StackTrace().GetFrames();

is it possible?





Aucun commentaire:

Enregistrer un commentaire