<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> <configuration>
    <runtime >   <runtime>
        <assemblyBinding >     <assemblyBinding>
            <supportPortability >      <supportPortability>

语法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 实现的应用程序(例如,.NET Framework 实现或 Silverlight 实现的 .NET Framework)提供支持。Beginning with the .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.

这种情况是必须同时引用特定引用程序集的 Silverlight 实现的 .NET Framework 实现和 .NET Framework 的程序集。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 实现和 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