Home  >  Article  >  类库下载  >  Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute

Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute

高洛峰
高洛峰Original
2016-10-14 17:09:491852browse

Core code

Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute

开 Expand the code in the graph, look at the arrow ↓

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.

Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute

Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute

Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute

Figure - Correspondence between the nouns in the "Assembly Information" dialog box and the AssemblyInfo.cs file

2. Informational properties

You can use informational properties to provide information for an assembly Other company or product information.

Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute

  3. Assembly Manifest Feature

  You can use the assembly manifest feature to provide information in the assembly manifest. These include title, description, default alias, and configuration.

Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute

4. Strong name feature (not in depth)

Usually exists in earlier versions of Visual Studio. To use a strong-named assembly, perform the following assembly-level features:

  ①AssemblyKeyFileAttribute

  ②AssemblyKeyNameAttribute

  ③AssemblyDelaySignAttribute

This is still supported, however, the preferred method of signing an assembly is to use the Signature Page. (Not going into details here)

2. Obsolete features

The Obsolete attribute indicates that a program entity is marked as one that is no longer recommended for use. Each use of an entity marked as obsolete will subsequently generate a warning or error based on the configuration attribute.

/// <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

Anatomy of AssemblyInfo.cs - Learn about commonly used attributes Attribute

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more