Udostępnij za pośrednictwem


Global Attributes (C# Programming Guide)

Most attributes are applied to specific language elements such as classes or methods; however, some attributes are global—they apply to an entire assembly or module. For example, the AssemblyVersionAttribute attribute can be used to embed version information into an assembly, like this:

[assembly: AssemblyVersion("1.0.0.0")]

Global attributes appear in the source code after any top-level using directives and before any type or namespace declarations. Global attributes can appear in multiple source files, but the files must be compiled in a single compilation pass.

These are some frequently used .NET Framework assembly-level attributes:

AssemblyCompanyAttribute

AssemblyConfigurationAttribute

AssemblyCopyrightAttribute

AssemblyCultureAttribute

AssemblyDescriptionAttribute

AssemblyProductAttribute

AssemblyTitleAttribute

AssemblyTrademarkAttribute

These attributes are used in projects based on the Visual Studio Windows Forms Application Template. This template includes a file called AssemblyInfo.cs, which includes these attribute instantiations:

[assembly: AssemblyTitle("WindowsApplication1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("WindowsApplication1")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2005")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Note

Assembly-level attributes are ignored if you are not creating an assembly.

Assembly Signing Attributes

In previous versions of Visual Studio, signing assemblies with strong names was performed with these assembly-level attributes

This is still supported, but the preferred way to sign assemblies is to use the Signing Page in the Project Designer. See Signing Page, Project Designer and How to: Sign an Assembly (Visual Studio) for more information.

See Also

Concepts

C# Programming Guide

Reference

System.Reflection

Attributes (C# Programming Guide)

Creating Custom Attributes (C# Programming Guide)

Accessing Attributes With Reflection (C# Programming Guide)

Other Resources

Common Attributes (C# Programming Guide)