Accessing AssemblyInfo in C#

To retrieve a program’s Assembly information, you need to access the System.Reflection.Assembly class.

First, retrieve the object for the currently executing assembly:

System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();

Next, retrieve the desired attributes by calling GetCustomAttributes() with the respective attribute type:

object[] rgobjP = asm.GetCustomAttributes(
    typeof(System.Reflection.AssemblyProductAttribute), false);
object[] rgobjV = asm.GetCustomAttributes(
    typeof(System.Reflection.AssemblyFileVersionAttribute), false);

If the attribute exists in the assembly, the object[] array has a length greater zero.

However, the AssemblyVersion (of type AssemblyVersionAttribute) is not accessible in this way, as iterating through the array

object[] rgobj = asm.GetCustomAttributes(false);

shows. Rather, you have to access the assembly’s asm.GetName().Version object.

See also this entry on codeproject with available source code.

1 thought on “Accessing AssemblyInfo in C#

  1. Pingback: AssemblyVersion and AssemblyFileVersion « devioblog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.