Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. getting attribute values from AssemblyInfo.cs

getting attribute values from AssemblyInfo.cs

Scheduled Pinned Locked Moved C#
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zuhx
    wrote on last edited by
    #1

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

    B 1 Reply Last reply
    0
    • Z zuhx

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

      B Offline
      B Offline
      Burt Harris
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups