ComCompatibleVersionAttribute 类

向 COM 客户端指示程序集当前版本中的所有类与该程序集早期版本中的类兼容。

**命名空间:**System.Runtime.InteropServices
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Assembly, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class ComCompatibleVersionAttribute
    Inherits Attribute
用法
Dim instance As ComCompatibleVersionAttribute
[AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class ComCompatibleVersionAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly, Inherited=false)] 
[ComVisibleAttribute(true)] 
public ref class ComCompatibleVersionAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class ComCompatibleVersionAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) 
ComVisibleAttribute(true) 
public final class ComCompatibleVersionAttribute extends Attribute

备注

可以将此属性应用到程序集。

默认情况下,类型库导出程序 (Tlbexp.exe) 使用程序集的版本号来计算类标识符 (CLSID)。每次导出新的程序集版本时,所有公共的、COM 可见的类都会获得新的 CLSID。

可以应用 ComCompatibleVersionAttribute 属性强制使程序集当前版本中的类的所有 CLSID 与其早期版本中的类的 CLSID 相同。只要 CLSID 保持相同,旧式 COM 应用程序便可以在卸载原始程序集之后,使用兼容程序集的更新版本。如果对某个类应用 System.Runtime.InteropServices.GuidAttribute 以显式设置其 CLSID,则 ComCompatibleVersionAttribute 不起作用。

程序集版本包含四个部分,由此属性的属性组合而成。始终应指定当前程序集可向后兼容的最低版本,以便使用该版本计算该程序集中的所有 CLSID。

示例

下面的示例演示了如何在具有更高版本号的程序集中指定程序集版本 1.0.0.0。无论新的程序集版本是什么,该程序集中的所有 CLSID 都将使用版本 1.0.0.0 生成,而不使用当前程序集版本。

Imports System
 Imports System.Runtime.Interop
 Assembly: AssemblyVersion ("3.0.0.0")
 Assembly: ComCompatibleVersionAttribute(1,0,0,0)
 Module MyNamespace
   Public Class MyClass
     ' Insert code.
   End Class
using System;
 using System.Runtime.InteropServices;
 [assembly: AssemblyVersion ("3.0.0.0")
 [assembly: ComCompatibleVersion(1,0,0,0)]
 namespace MyNamespace
 {
   class MyClass
   {
     // Insert code.
   }
 }

继承层次结构

System.Object
   System.Attribute
    System.Runtime.InteropServices.ComCompatibleVersionAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1

请参见

参考

ComCompatibleVersionAttribute 成员
System.Runtime.InteropServices 命名空间
GuidAttribute

其他资源

类型库导出程序 (Tlbexp.exe)