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

用以下格式指定要使用的程序集的版本,而不是最初请求的版本:Specifies 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