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

前端 未结 2 1449
佛祖请我去吃肉
佛祖请我去吃肉 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:53

    You can get assembly info from different properties AssemblyVersion, AssemblyFileVersion and AssemblyDescription.

                    /// 
                    /// This class provide inforamtion about product version.
                    /// 
                    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();
                            }
                        }
    
    
    
                    }
    

提交回复
热议问题