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.

One Response to Accessing AssemblyInfo in C#

  1. […] noticed that I wrote about this topic many years ago, but I didn’t remember, and probably you didn’t either […]

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: