Understanding the Visual Studio AssemblyInfo Class

This article is also available on the Microsoft TechNet Wiki.

This article won a silver medal in The Microsoft TechNet Guru Awards! (September 2015).

Overview

The AssemblyInfo Class holds application attributes about a Visual Studio project that are applied at the assembly level. These global assembly attributes can be information on the company, product, or even the languages it supports. The class is created automatically within the project and is housed in the Properties folder.

Setting the attributes

Setting attributes of the AssemblyInfo class can be accomplished two ways:

  • through the Assembly Information dialog box of your project’s Properties.
  • through the AssemblyInfo.cs file located within your Solution Explorer.

Assembly Information dialog box

To access the Assembly Information dialog box, double click the Properties file within your project’s solution on the Solution Explorer. This will raise the Properties Editor. Select the Application tab and then click the Assembly Information button to open the Assembly Information dialog box.

AIC01

Modify the fields within the dialog box and click OK to save your settings. All changes will be saved within the AssemblyInfo.cs file. For more information on the Assembly Information Dialog Box, see Assembly Information Dialog Box.

AIC02

AssemblyInfo.cs file

All of the information saved within the Assembly Information dialog box gets stored in the AssemblyInfo.cs file. This class file is maintained by Visual Studio and can be seen by expanding the Properties node in the Solution Explorer.

Open the file to see the project information located within the Assembly Information attributes. You can modify these attributes here for quicker editing instead of using the GUI editor.

AIC03

Assembly Information attributes

The Assembly Information attributes are designed to house specific information about your project. The following table shows each attribute’s function:

Attribute Function
[AssemblyTitle] Specifies a title for the assembly.
[AssemblyDescription] A description of the product or modules that comprise the assembly.
[AssemblyConfiguration] Specifies the build configuration, such as debug or release.
[AssemblyCompany] Holds company information.
[AssemblyProduct] Displays product information.
[AssemblyCopyright] Holds copyright information for product or assembly.
[AssemblyTrademark] Assembly or product trademark information.
[AssemblyCulture] Provides information on what languages the assembly supports.

Accessing the attributes through code

To access the values of the AssemblyInfo.cs file within your C# code you will need to employ the System.Reflection namespace. The following code sample shows how to extract this information for your project:

        public static void Main()
        {
            string company = ((AssemblyCompanyAttribute)Attribute.GetCustomAttribute(
                Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute), false))
               .Company;
            Console.WriteLine(company);
 
            string copyright = ((AssemblyCopyrightAttribute)Attribute.GetCustomAttribute(
                Assembly.GetExecutingAssembly(), typeof(AssemblyCopyrightAttribute), false))
               .Copyright;
            Console.WriteLine(copyright);
 
            Console.ReadLine();
        }

AIC04

Conclusion

This article showed where assembly level metadata is stored for your projects. It also demonstrated how to modify this information, what the field attributes are used for, and then how to use them within your code. Since each project receives an AssemblyInfo.cs file automatically, you now know how to prepare this information for use within your projects.

References

Advertisements

About Ken Cenerelli
I am a Programmer Writer, .NET Developer, Microsoft MVP - Visual Studio and Development Technologies, Public Speaker, Blogger, and Microsoft Azure Nerd. I blog regularly at kencenerelli.wordpress.com and can be found on Twitter via @KenCenerelli.

One Response to Understanding the Visual Studio AssemblyInfo Class

  1. Pingback: Microsoft Technical Guru – September 2015 | Ken Cenerelli

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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: