TargetFrameworkAttribute 类

定义

标识编译特定程序集时所针对的 .NET Framework 的版本。Identifies the version of the .NET Framework that a particular assembly was compiled against.

public ref class TargetFrameworkAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)]
public sealed class TargetFrameworkAttribute : Attribute
type TargetFrameworkAttribute = class
    inherit Attribute
Public NotInheritable Class TargetFrameworkAttribute
Inherits Attribute
继承
TargetFrameworkAttribute
属性

注解

TargetFrameworkAttribute 类提供一个特性,可将该特性应用于程序集,以指示生成程序集时所针对的 .NET Framework 运行时的版本。The TargetFrameworkAttribute class provides an attribute that you can apply to an assembly to indicate the version of the .NET Framework runtime against which the assembly was built. 例如,下面的示例将 TargetFrameworkAttribute 应用于程序集,以指示该程序集是使用 .NET Framework 4.NET Framework 4生成的。For example, the following example applies the TargetFrameworkAttribute to an assembly to indicate that it was built using .NET Framework 4.NET Framework 4.

using System;
using System.Runtime.Versioning;

[assembly:TargetFramework(".NETFramework,Version=v4.0")]

namespace MyCompany.Utilities
{
   public class StringLibrary
   {
      // Members defined here.
   }
}
Imports System.Runtime.Versioning

<Assembly:TargetFramework(".NETFramework,Version=v4.0)")>

Namespace MyCompany.Utilities
   Public Class StringLibrary
      ' Members defined here.
   End Class
End Namespace

TargetFrameworkAttribute 类构造函数具有单个参数 frameworkName,该参数指定生成程序集所基于的 .NET Framework 版本。The TargetFrameworkAttribute class constructor has a single parameter, frameworkName, that specifies the .NET Framework version against which the assembly was built. 此参数映射到 FrameworkName 属性。This parameter maps to the FrameworkName property. 此外,TargetFrameworkAttribute 属性还可以指定 FrameworkDisplayName 属性,以提供更具描述性的 .NET Framework 版本字符串,以便向程序集的客户端显示。In addition, the TargetFrameworkAttribute attribute can specify a FrameworkDisplayName property to provide a more descriptive .NET Framework version string that is suitable for displaying to clients of the assembly. 下面的示例将 TargetFrameworkAttribute 应用于程序集,并同时分配两个属性值,以指示该程序集是使用 .NET Framework 4.NET Framework 4生成的。The following example applies the TargetFrameworkAttribute to an assembly and assigns both property values to indicate that the assembly was built using .NET Framework 4.NET Framework 4.

using System;
using System.Runtime.Versioning;

[assembly:TargetFramework(".NETFramework,Version=v4.0", 
          FrameworkDisplayName = ".NET Framework, Version 4.0")]

namespace MyCompany.Utilities
{
   public class StringLibrary
   {
      // Members defined here.
   }
}
Imports System.Runtime.Versioning

<Assembly:TargetFramework(".NETFramework,Version=v4.0)", _
          FrameworkDisplayName := ".NET Framework, Version 4.0")>

Namespace MyCompany.Utilities
   Public Class StringLibrary
      ' Members defined here.
   End Class
End Namespace

构造函数

TargetFrameworkAttribute(String)

通过指定一个程序集在生成时针对的 .NET Framework 版本,初始化 TargetFrameworkAttribute 类的实例。Initializes an instance of the TargetFrameworkAttribute class by specifying the .NET Framework version against which an assembly was built.

属性

FrameworkDisplayName

获取生成某个程序集时针对的 .NET Framework 版本的显示名称。Gets the display name of the .NET Framework version against which an assembly was built.

FrameworkName

获取编译某个特定程序集时针对的 .NET Framework 版本的名称。Gets the name of the .NET Framework version against which a particular assembly was compiled.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅