Using Assembly Attributes

The word assembly is used in several contexts. There is the Assembly class that represents an instance of a compiled assembly. There is the notion of a compiled assembly that contains metadata and IL, and there is the Assembly keyword used to demark assembly-level attributes. You will most commonly find assembly-level attributes in a file named AssemblyInfo.vb , although you may find assembly-level attributes in any module.

Two things are required for assembly-level attributes. The first is that when the attribute is defined, it must have the AttributeTargets.All or AttributeTargets.Assembly enumerated value in the list of arguments used to initialize the AttributeUsageAttribute . The second requirement is that you must use the Assembly keyword followed by a colon ( : ) in the attribute statement. (Refer to the Creating Custom Attributes section later in this chapter for more information on the AttributeUsageAttribute .) The next fragment demonstrates a common assembly-level attribute you will find in the AssemblyInfo.vb file.

 <Assembly: AssemblyCompany("Software Conceptions, Inc.")> 

The preceding assembly-level attribute adds company information to aid in identifying the originator of the assembly. The value of attributes can be reflected or, as is the case with attributes used to identify code authors, you can use the FileVersionInfo class to retrieve information consistent with what you might expect to find in an About dialog.


By convention assembly-level attributes have an Assembly prefix and an Attribute suffix. The suffix is used by convention when naming attribute classes but dropped when the attribute is applied (as in the code above).

The next section demonstrates an example of using assembly-level attributes to create a brief About dialog.

Visual Basic. NET Power Coding
Visual Basic(R) .NET Power Coding
ISBN: 0672324075
EAN: 2147483647
Year: 2005
Pages: 215
Authors: Paul Kimmel © 2008-2017.
If you may any questions please contact us: