getting attribute values from AssemblyInfo.cs
-
I am trying to get assembly info from the AssemblyInfo.cs file, but for some reason I get a null returned for attributes that I specified. Specifically, I provided values for the AssemblyTitle and AssemblyDescription field but both return empty. Any ideas on this ? public ArrayList GetOmsList() { ArrayList drivers = new ArrayList(); DirectoryInfo driversFolder = new DirectoryInfo(dirPath); //direcotry path of drivers if (driversFolder.Exists.Equals(false)) { Console.WriteLine("Drivers Path Does Not Exist"); //break out of the following code } FileInfo[] allFiles = driversFolder.GetFiles("*.dll"); if (allFiles.Length == 0) { Console.WriteLine("No Dlls Found"); } foreach (FileInfo f in allFiles) { string fileName = f.FullName; try { Assembly a = Assembly.LoadFrom(fileName); Type[] types = a.GetTypes(); foreach (Type t in types) { if (t.GetInterface("IDriver", true) != null) { object[] attributes = a.GetCustomAttributes(true); foreach (object attribute in attributes) { if (attribute is AssemblyTitleAttribute) { drivers.Add("title"+((AssemblyTitleAttribute)attribute).Title); } else if (attribute is AssemblyDescriptionAttribute) { drivers.Add(attribute); drivers.Add("descript"+((AssemblyDescriptionAttribute)attribute).Description); } } drivers.Add(t.Name); Console.WriteLine(t.FullName + " Implements Driver Interface"); } } } catch (Exception e) { Console.WriteLine(e.Message.ToString()); } } return drivers; }
-
I am trying to get assembly info from the AssemblyInfo.cs file, but for some reason I get a null returned for attributes that I specified. Specifically, I provided values for the AssemblyTitle and AssemblyDescription field but both return empty. Any ideas on this ? public ArrayList GetOmsList() { ArrayList drivers = new ArrayList(); DirectoryInfo driversFolder = new DirectoryInfo(dirPath); //direcotry path of drivers if (driversFolder.Exists.Equals(false)) { Console.WriteLine("Drivers Path Does Not Exist"); //break out of the following code } FileInfo[] allFiles = driversFolder.GetFiles("*.dll"); if (allFiles.Length == 0) { Console.WriteLine("No Dlls Found"); } foreach (FileInfo f in allFiles) { string fileName = f.FullName; try { Assembly a = Assembly.LoadFrom(fileName); Type[] types = a.GetTypes(); foreach (Type t in types) { if (t.GetInterface("IDriver", true) != null) { object[] attributes = a.GetCustomAttributes(true); foreach (object attribute in attributes) { if (attribute is AssemblyTitleAttribute) { drivers.Add("title"+((AssemblyTitleAttribute)attribute).Title); } else if (attribute is AssemblyDescriptionAttribute) { drivers.Add(attribute); drivers.Add("descript"+((AssemblyDescriptionAttribute)attribute).Description); } } drivers.Add(t.Name); Console.WriteLine(t.FullName + " Implements Driver Interface"); } } } catch (Exception e) { Console.WriteLine(e.Message.ToString()); } } return drivers; }
I think those two attributes are converted into information in a version resource, and not retained as attributes. You should be able to access them via
FileVersionInfo.GetVersionInfo()
. Burt Harris