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.

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.

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.

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

 

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