Home >类库下载 >C# class library >Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute
using System.Reflection; using System.Runtime.InteropServices; // 有关程序集的常规信息通过下列特性集 // 控制。更改这些特性值可修改 // 与程序集关联的信息。 [assembly: AssemblyTitle("MusicStore")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Microsoft")] [assembly: AssemblyProduct("MusicStore")] [assembly: AssemblyCopyright("Copyright © Microsoft 2016")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // 将 ComVisible 设置为 false 会使此程序集中的类型 // 对 COM 组件不可见。如果需要 // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 [assembly: ComVisible(false)] // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID [assembly: Guid("a9ef3281-9049-4a52-a2f1-2061d442200e")] // 程序集的版本信息由下列四个值组成: // // 主版本 // 次版本 // 内部版本号 // 修订版本 // // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, // 方法是按如下所示使用 "*": [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]E I. Global attributes Most characteristics are suitable for specific language elements (such as class or methods), but some attributes are global they are applicable. to the entire assembly or module. For example: AssemblyVersionAttribute attribute can be used to embed version information into an assembly. Global attributes appear in source code before any top-level using directives and before any type, module or namespace declarations. Global attributes can appear in multiple source files, however, the files must be compiled in a single compile pass. In C# projects, they are in the AssemblyInfo.cs file. Assembly attributes are values that provide information about the assembly. They are divided into the following categories: ①Assembly identification characteristics ②Informational characteristics ③Assembly manifest characteristics ④Strong name characteristics 1. Assembly identification characteristics Three characteristics (use strong names , if applicable) Determine the assembly's identity: name, version, and culture. When referenced in code, these attributes form the full name of the assembly required. Using attributes, you can set the version and culture of an assembly. However, the name value is set by the compiler, in the Assembly Information dialog box of the Visual Studio IDE, after the assembly is created, according to the file that contains the assembly manifest. The AssemblyFlagsAttribute attribute specifies whether multiple copies of an assembly can coexist.
/// <summary> /// 旧类 /// </summary> [Obsolete("请使用 " + nameof(NewClass))] class OldClass { public void Method() { } } /// <summary> /// 新类 /// </summary> class NewClass { [Obsolete("请使用 " + nameof(NewMethod), true)] public void OldMethod() { } public void NewMethod() { } }rrree