<supportPortability > 元素<supportPortability> Element

通过禁用将程序集视为等效于应用程序可移植性用途的默认行为来指定应用程序可以在两种不同的 .NET Framework 实现中引用同一程序集。Specifies that an application can reference the same assembly in two different implementations of the .NET Framework, by disabling the default behavior that treats the assemblies as equivalent for application portability purposes.

<配置 > 元素<configuration> Element
<运行时 > 元素<runtime> Element
<assemblyBinding > 元素<assemblyBinding> Element
<supportPortability > 元素<supportPortability> Element

语法Syntax

<supportPortability PKT="public_key_token" enabled="true|false"/>  

特性和元素Attributes and Elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

特性Attribute 描述Description
PKTPKT 必需的特性。Required attribute.

以字符串形式指定受影响的程序集的公钥标记。Specifies the public key token of the affected assembly, as a string.
enabledenabled 可选特性。Optional attribute.

指定是否应启用对指定的.NET Framework 程序集实现之间的可移植性的支持。Specifies whether support for portability between implementations of the specified .NET Framework assembly should be enabled.

enabled 特性enabled Attribute

“值”Value 描述Description
truetrue 启用对指定的.NET Framework 程序集实现之间的可移植性的支持。Enable support for portability between implementations of the specified .NET Framework assembly. 这是默认设置。This is the default.
Falsefalse 禁用对指定的.NET Framework 程序集实现之间的可移植性的支持。Disable support for portability between implementations of the specified .NET Framework assembly. 这使应用程序具有对指定的程序集的多个实现的引用。This enables the application to have references to multiple implementations of the specified assembly.

子元素Child Elements

无。None.

父元素Parent Elements

元素Element 描述Description
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime 包含有关程序集绑定和垃圾回收的信息。Contains information about assembly binding and garbage collection.
assemblyBinding 包含有关程序集版本重定向和程序集位置的信息。Contains information about assembly version redirection and the locations of assemblies.

备注Remarks

.NET Framework 4.NET Framework 4,支持自动提供的应用程序可以使用两种实现的.NET Framework 中,例如.NET Framework 实现或.NET Framework for Silverlight 实现。Beginning with the .NET Framework 4.NET Framework 4, support is automatically provided for applications that can use either of two implementations of the .NET Framework, for example either the .NET Framework implementation or the .NET Framework for Silverlight implementation. 程序集绑定器将特定的.NET Framework 程序集的两个实现视为等效。The two implementations of a particular .NET Framework assembly are seen as equivalent by the assembly binder. 在少数情况下,此应用程序可移植性功能会导致问题。In a few scenarios, this application portability feature causes problems. 在这些情况下,<supportPortability>元素可用于禁用该功能。In those scenarios, the <supportPortability> element can be used to disable the feature.

其中一种方案是具有要引用的.NET Framework 实现和.NET Framework for Silverlight 实现的特定引用程序集的程序集。One such scenario is an assembly that has to reference both the .NET Framework implementation and the .NET Framework for Silverlight implementation of a particular reference assembly. 例如,编写 Windows Presentation Foundation (WPF) 中的 XAML 设计器可能需要引用这两个 WPF 桌面实现,用于在设计器用户界面和 Silverlight 实现中包含的 WPF 子集。For example, a XAML designer written in Windows Presentation Foundation (WPF) might need to reference both the WPF Desktop implementation, for the designer's user interface, and the subset of WPF that is included in the Silverlight implementation. 默认情况下,单独引用会导致编译器错误,因为程序集绑定将这两个程序集视为等效。By default, the separate references cause a compiler error, because assembly binding sees the two assemblies as equivalent. 此元素禁用默认行为,并允许编译成功。This element disables the default behavior, and allows compilation to succeed.

重要

为了使编译器能够将信息传递到公共语言运行时的程序集绑定逻辑,必须使用/appconfig编译器选项指定包含此元素的 app.config 文件的位置。In order for the compiler to pass the information to the common language runtime's assembly-binding logic, you must use the /appconfig compiler option to specify the location of the app.config file that contains this element.

示例Example

以下示例启用应用程序能够对.NET Framework 实现和.NET Framework for Silverlight 实现这两个实现中存在任何.NET Framework 程序集的引用。The following example enables an application to have references to both the .NET Framework implementation and the .NET Framework for Silverlight implementation of any .NET Framework assembly that exists in both implementations. /appconfig编译器选项必须用于指定此 app.config 文件的位置。The /appconfig compiler option must be used to specify the location of this app.config file.

<configuration>  
   <runtime>  
      <assemblyBinding>  
         <supportPortability PKT="7cec85d7bea7798e" enable="false"/>  
         <supportPortability PKT="31bf3856ad364e35" enable="false"/>  
      </assemblyBinding>  
   </runtime>  
</configuration>  

请参阅See also