This documentation is archived and is not being maintained.

Global Attributes

Most attributes are attached to specific language elements such as classes or methods. However, some attributes are global — they can apply to an entire assembly or module. You specify assembly-level attributes using the following syntax:

<Assembly: Attribute1, Assembly: Attribute2..., Assembly: Attributen>

You specify module-level attributes using similar syntax:

<Module: Attribute1, Module: Attribute2..., Module: Attributen>

You place global attributes in source code after any top-level directives, such as Option Explicit and Imports statements, but before any type or namespace declarations. Global attributes can appear in multiple source files in a project, but they are generally placed in the file AssemblyInfo.vb file created automatically with Visual Basic .NET projects.

Assembly Attributes

Assembly attributes are values that provide information about an assembly. They fall into the following categories:

  • Assembly identity attributes
  • Informational attributes
  • Assembly manifest attributes
  • Strong name attributes

Assembly Identity Attributes

Three attributes (with a strong name, if applicable) determine the identity of an assembly: name, version, and culture. These attributes form the full name of the assembly and are required when referencing it in code. You can set an assembly's version and culture using attributes. The name value, however, is set by the compiler or the Assembly Linker (Al.exe) when the assembly is created, based on the file containing the assembly manifest. The AssemblyFlags attribute specifies whether multiple copies of the assembly can coexist.

The following table shows the identity attributes.

Attribute Purpose
AssemblyName Class Fully describes an assembly's identity
AssemblyVersionAttribute Class Specifies the version of an assembly
AssemblyCultureAttribute Class Specifies which culture the assembly supports
AssemblyFlagsAttribute Class Specifies whether an assembly supports side-by-side execution on the same machine, in the same process, or in the same application domain

The following code applies the version and culture attributes to an assembly:

'Set version number for assembly.
'Set culture as German.

Informational Attributes

You can use informational attributes to provide additional company or product information for an assembly. The following table shows the informational attributes defined in the System.Reflection namespace.

Attribute Purpose
AssemblyProductAttribute Class Defines a product name custom attribute for an assembly manifest
AssemblyTrademarkAttribute Class Defines a trademark custom attribute for an assembly manifest
AssemblyInformationalVersionAttribute Class Defines an assembly informational version custom attribute for an assembly manifest
AssemblyCompanyAttribute Class Defines a company name custom attribute for an assembly manifest
AssemblyCopyrightAttribute Class Defines a copyright custom attribute for an assembly manifest
AssemblyFileVersionAttribute Class Instructs the compiler to use a specific version number for the Win32 file version resource

Assembly Manifest Attributes

You can use assembly manifest attributes to provide information in the assembly manifest, including title, description, default alias, and configuration. The following table shows the assembly manifest attributes defined in the System.Reflection namespace.

Attribute Purpose
AssemblyTitleAttribute Class Defines an assembly title custom attribute for an assembly manifest
AssemblyDescriptionAttribute Class Defines an assembly description custom attribute for an assembly manifest
AssemblyConfigurationAttribute Class Defines an assembly configuration custom attribute (such as retail or debug) for an assembly manifest
AssemblyDefaultAliasAttribute Class Defines a friendly default alias for an assembly manifest

Strong Name Attributes

Strong names are unique identifiers that protect the identity and integrity of an assembly. You can use strong name attributes to set a strong name for an assembly. The following table shows the strong name attributes defined in the System.Reflection namespace.

Attribute Purpose
AssemblyDelaySignAttribute Class Boolean that indicates whether you want to reserve space in the executable file for the strong name signature, but defer the actual signing until some later stage. For more information, see Delay Signing an Assembly.
AssemblyKeyFileAttribute Class Indicates the file that contains a key. The location of the KeyFile should be relative to the project output directory, which is %Project Directory%\obj\<configuration>. For example, if your KeyFile is located in the project directory, you would specify the AssemblyKeyFile attribute as

[assembly: AssemblyKeyFile("..\\..\\mykey.snk")]

AssemblyKeyNameAttribute Class Refers to a key that has been installed in the Crypto Service Provider (CSP) on your machine. You must specify a key in order for your file to be signed.

If the KeyFile and the KeyName values are both specified, the following processing occurs:

  • If the KeyName can be found in the CSP, that key is used.
  • If the KeyName does not exist and the KeyFile does exist, the key in the KeyFile is installed into the CSP and used.
  • For more information, see Assembly Security Considerations.

Signing Assemblies

You can sign an assembly in two different, but complementary ways: with a strong name or using the File Signing Tool (Signcode.exe). Signing an assembly with a strong name adds a public key encryption to the file containing the assembly manifest. Strong name signing ensures name uniqueness, prevents name spoofing and provides callers with some identity when a reference is resolved. For more information, see Signing an Assembly with a Strong Name.

To sign an assembly with a strong name

  1. Use the Strong Name Tool (Sn.exe) to generate a key file containing a key pair.
  2. Add strong name attributes to the AssemblyInfo.vb file created automatically with Visual Basic .NET projects. You can edit this file by double clicking its name in the Solution Explorer.

The following example uses delay signing to create a strong-named assembly with a public key file called myKey.snk.

<Assembly: AssemblyKeyFile("myKey.snk")> 
<Assembly: AssemblyDelaySign(True)> 
Note   Assembly-level attributes are ignored if you are not creating an assembly, such as when compiling from the command line using the /target:module option.

See Also

AssemblyFlagsAttribute Class | AssemblyName Class | AssemblyVersionAttribute Class | AssemblyCultureAttribute Class | AssemblyProductAttribute Class | AssemblyTrademarkAttribute Class | AssemblyInformationalVersionAttribute Class | AssemblyCompanyAttribute Class | AssemblyCopyrightAttribute Class | AssemblyFileVersionAttribute Class | AssemblyTitleAttribute Class | AssemblyDescriptionAttribute Class | AssemblyConfigurationAttribute Class | AssemblyDefaultAliasAttribute Class | AssemblyDelaySignAttribute Class | AssemblyKeyFileAttribute Class | AssemblyKeyNameAttribute Class | Custom Attributes | Defining Your Own Attributes | Application of Attributes | Strong Name Tool (Sn.exe) | Signing an Assembly with a Strong Name | File Signing Tool (Signcode.exe) | Assembly Security Considerations