rbulph Posted January 17, 2007 Posted January 17, 2007 How do I get hold of the properties of an dll? I want to know its name, the date it was created, and the Company information, all as shown in the Properties dialogue which you get by right-clicking on it in Explorer. It's a plug-in, so I'm finding it with code like below, which means that my starting point is an Assembly object. <vb> Dim strDLLs() As String, intIndex As Integer Dim objDLL As Assembly 'Go through all DLLs in the application's directory. strDLLs = Directory.GetFileSystemEntries(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "*.dll") For intIndex = 0 To strDLLs.Length - 1 Try objDLL = Assembly.LoadFrom(strDLLs(intIndex))...</vb> Quote
mskeel Posted January 17, 2007 Posted January 17, 2007 Here's a helper class for you This is in C# but it shouldn't be too hard to translate to VB. Feel free to modify it however you need. It should help you with some of the info you're looking for. Things like the date you can get from the one of the IO classes (either File, Path, or I think there's a FileProperties class, I'd have to look it up). If you have any questions, just let me know. Whew..I haven't looked at this code in a while and it could use a little polish, but the functionality is all there. namespace BKTech.Utilities { using System; using System.Reflection; ///<summary>Helper class for AssemblyInfo classes.</summary> ///<remarks>This class has been adapted from a class originally from the Microsoft XML comment maker.</remarks> public class AssemblyInfoHelper { //Used by Helper Functions to access information from Assembly Attributes private Type _type; ///<summary>Creates a new assmebly information helper</summary> ///<param name='applicationType'>The type of the application this assembly info helper class is built into.</param> ///<remarks>In most cases the paramater will be filled in using the GetType(Object as Type) function where Object is the assembly /// this helper class will be helping.</remarks> public AssemblyInfoHelper(Type applicationType) { _type = applicationType; } ///<summary>Gets the name of the assembly.</summary> public string AsmName { get { return _type.Assembly.GetName().Name.ToString(); } } ///<summary>Gets the full name of the assembly.</summary> public string AsmFQName { get { return _type.Assembly.GetName().FullName.ToString(); } } ///<summary>Gets the code base of the assembly.</summary> public string CodeBase { get { return _type.Assembly.CodeBase; } } ///<summary>Gets the copyright string of the assembly.</summary> public string Copyright { get { Type at = typeof(AssemblyCopyrightAttribute); Object[] r = _type.Assembly.GetCustomAttributes(at, false); AssemblyCopyrightAttribute ct = (AssemblyCopyrightAttribute)r[0]; return ct.Copyright; } } /// <summary>Gets the company to whom this assembly belongs.</summary> public string Company { get { Type at = typeof(AssemblyCompanyAttribute); Object[] r = _type.Assembly.GetCustomAttributes(at, false); AssemblyCompanyAttribute ct = (AssemblyCompanyAttribute)r[0]; return ct.Company; } } ///<summary>Gets a breif description of this assembly.</summary> public string Description { get { Type at = typeof(AssemblyDescriptionAttribute); Object[] r = _type.Assembly.GetCustomAttributes(at, false); AssemblyDescriptionAttribute da = (AssemblyDescriptionAttribute)r[0]; return da.Description; } } ///<summary>Gets the product of which this assembly is a part.</summary> public string Product { get { Type at = typeof(AssemblyProductAttribute); Object[] r = _type.Assembly.GetCustomAttributes(at, false); AssemblyProductAttribute pt = (AssemblyProductAttribute)r[0]; return pt.Product; } } ///<summary>Gets the official title of this assembly.</summary> public string Title { get { Type at = typeof(AssemblyTitleAttribute); Object[] r = _type.Assembly.GetCustomAttributes(at, false); AssemblyTitleAttribute ta = (AssemblyTitleAttribute)r[0]; return ta.Title; } } ///<summary>Gets the version number of this assembly.</summary> public string Version { get { return _type.Assembly.GetName().Version.ToString(); } } /// <summary>Gets the trademark information of this assembly.</summary> public string Trademark { get { Type at = typeof(AssemblyTrademarkAttribute); Object[] r = _type.Assembly.GetCustomAttributes(at, false); AssemblyTrademarkAttribute ta = (AssemblyTrademarkAttribute)r[0]; return ta.Trademark; } } } //end class } //end namespace Quote
rbulph Posted January 17, 2007 Author Posted January 17, 2007 Thanks. The following shows how to get the info I need in VB: Dim sName As String = My.Computer.FileSystem.GetName(strDLLs(0)) Dim sCompanyName As String Dim aca() As System.Reflection.AssemblyCompanyAttribute = objDLL.GetCustomAttributes(GetType(AssemblyCompanyAttribute), True) If Not aca Is Nothing Then sCompanyName = aca(0).Company Dim sDate As String = FileSystem.FileDateTime(strDLLs(0)).Date Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.