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

SyntaxSyntax

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

以字串形式指定受影響元件的公開金鑰 token。Specifies the public key token of the affected assembly, as a string.
已啟用enabled 選擇性屬性。Optional attribute.

指定是否應啟用指定 .NET Framework 元件之實執行之間的可攜性支援。Specifies whether support for portability between implementations of the specified .NET Framework assembly should be 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.

其中一個這類案例是必須同時參考 .NET Framework 的執行和 .NET Framework 的元件,以進行特定參考元件的 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.

重要

為了讓編譯器將資訊傳遞給 common language runtime 的元件系結邏輯,您必須使用 /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 執行和 .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