<bindingRedirect > 元素<bindingRedirect> Element

將一個組件版本重新導向至另一個版本。Redirects one assembly version to another.

<configuration> <configuration>
   <執行時間 >   <runtime>
     <assemblyBinding >     <assemblyBinding>
       <dependentAssembly >       <dependentAssembly>
         <bindingRedirect>        <bindingRedirect>

語法Syntax

   <bindingRedirect    
oldVersion="existing assembly version"  
newVersion="new assembly version"/>  

屬性和項目Attributes and Elements

下列各節描述屬性、子項目和父項目。The following sections describe attributes, child elements, and parent elements.

屬性Attributes

屬性Attribute 說明Description
oldVersion 必要屬性。Required attribute.

指定原本要求的組件版本。Specifies the version of the assembly that was originally requested. 元件版本號碼的格式為 [主要. 次要. 組建. 修訂]。The format of an assembly version number is major.minor.build.revision. 這個版本號碼每個部分的有效值為 0 至 65535。Valid values for each part of this version number are 0 to 65535.

您也可以使用下列格式指定版本範圍:You can also specify a range of versions in the following format:

n.n.n.n - n.n.n.nn.n.n.n - n.n.n.n
newVersion 必要屬性。Required attribute.

以下列格式指定要使用的元件版本,而不是原始要求的版本: n . n. n. nSpecifies the version of the assembly to use instead of the originally requested version in the format: n.n.n.n

這個值可以指定 oldVersion 以前的版本。This value can specify an earlier version than oldVersion.

子元素Child Elements

項目Element 描述Description
None

父項目Parent Elements

項目Element 說明Description
assemblyBinding 包含有關組件版本重新導向和組件位置的資訊。Contains information about assembly version redirection and the locations of assemblies.
configuration 通用語言執行平台和 .NET Framework 應用程式所使用之每個組態檔中的根項目。The root element in every configuration file used by the common language runtime and .NET Framework applications.
dependentAssembly 封裝每一個組件的繫結原則和組件位置。Encapsulates binding policy and assembly location for each assembly. 針對每個組件使用一個 dependentAssembly 項目。Use one dependentAssembly element for each assembly.
runtime 包含有關組件繫結和記憶體回收的資訊。Contains information about assembly binding and garbage collection.

備註Remarks

當您對照強式名稱的組件建置 .NET Framework 應用程式時,即使有可用的新版本,應用程式仍會預設為在執行階段使用該組件版本。When you build a .NET Framework application against a strong-named assembly, the application uses that version of the assembly at run time by default, even if a new version is available. 不過,您可以設定應用程式以較新的組件版本執行。However, you can configure the application to run against a newer version of the assembly. 如需執行時間如何使用這些檔案來判斷要使用哪個元件版本的詳細資訊,請參閱執行時間如何找出元件For details on how the runtime uses these files to determine which assembly version to use, see How the Runtime Locates Assemblies.

您可以在 bindingRedirect 項目中包含多個 dependentAssembly 項目,藉此重新導向多個組件版本。You can redirect more than one assembly version by including multiple bindingRedirect elements in a dependentAssembly element. 您也可以將組件從較新版本重新導向至較舊版本。You can also redirect from a newer version to an older version of the assembly.

在應用程式組態檔中進行明確的組件繫結重新導向必須擁有安全性權限。Explicit assembly binding redirection in an application configuration file requires a security permission. 這適用於 .NET Framework 組件和協力廠商組件的重新導向。This applies to redirection of .NET Framework assemblies and assemblies from third parties. 許可權是藉由SecurityPermissionFlag SecurityPermission在上設定旗標來授與。The permission is granted by setting the SecurityPermissionFlag flag on the SecurityPermission. 如需詳細資訊,請參閱元件系結重新導向安全性許可權For more information, see Assembly Binding Redirection Security Permission.

範例Example

下列範例將示範如何將某一個組件版本重新導向至另一個版本。The following example shows how to redirect one assembly version to another.

<configuration>  
   <runtime>  
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
         <dependentAssembly>  
            <assemblyIdentity name="myAssembly"  
                              publicKeyToken="32ab4ba45e0a69a1"  
                              culture="neutral" />  
            <bindingRedirect oldVersion="1.0.0.0"  
                             newVersion="2.0.0.0"/>  
         </dependentAssembly>  
      </assemblyBinding>  
   </runtime>  
</configuration>  

另請參閱See also