How can I retrieve the 'AssemblyCompany' setting (in AssemblyInfo.cs)?

Jonathan picture Jonathan · Jun 27, 2010 · Viewed 31k times · Source

Is it possible to retrieve this value at runtime?

I'd like to keep the value in one place, and retrieve it whenever my application needs to output the name of my company.

Answer

Sandor Drieënhuizen picture Sandor Drieënhuizen · Jun 27, 2010

This should do it:

using System.Reflection;

string company = ((AssemblyCompanyAttribute)Attribute.GetCustomAttribute(
    Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute), false))
   .Company;

If you really want to keep the value in one place and you have multiple assemblies in your solution, you could either:

  • Use GetEntryAssembly instead of GetExecutingAssembly and set the company attribute only on your entry assembly, or better:
  • Use a central assembly info file, see this answer

UPDATE Improved the code by suggestion of @hmemcpy so it doesn't need [0] anymore. Thanks!