<bindingRedirect> 元素

将一个程序集版本重定向到另一个程序集版本。

<配置>
   <运行时>
     <assemblyBinding>
       <dependentAssembly>
         <bindingRedirect>

Syntax

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

特性和元素

下列各节描述了特性、子元素和父元素。

特性

Attribute Description
oldVersion 必需属性。

指定最初请求的程序集的版本。 程序集版本号的格式为 major.minor.build.revision。 此版本号的每个部分的有效值为 0 到 65535。

还可以使用以下格式指定一系列版本:

n.n.n.n - n.n.n.n
newVersion 必需属性。

指定要使用的程序集版本,而不是采用以下格式的原始请求版本: n.n.n.n

此值可以指定早于 oldVersion.

子元素

元素 Description
None

父元素

元素 Description
assemblyBinding 包含有关程序集版本重定向和程序集位置的信息。
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。
dependentAssembly 封装每个程序集的绑定策略和程序集位置。 对每个程序集使用一个 dependentAssembly 元素。
runtime 包含有关程序集绑定和垃圾回收的信息。

注解

针对强命名程序集生成 .NET Framework 应用程序时,应用程序默认在运行时使用该版本的程序集,即使新版本可用也是如此。 但是,可以将应用程序配置为针对较新版本的程序集运行。 有关运行时如何使用这些文件来确定要使用的程序集版本的详细信息,请参阅 运行时如何查找程序集

可以通过在元素中包含bindingRedirect多个dependentAssembly元素来重定向多个程序集版本。 还可以从较新版本重定向到旧版本的程序集。

应用程序配置文件中的显式程序集绑定重定向需要安全权限。 这适用于从第三方重定向 .NET Framework 程序集和程序集。 通过 SecurityPermissionFlag 设置标记 SecurityPermission授予权限。 有关详细信息,请参阅 程序集绑定重定向安全权限

Example

以下示例演示如何将一个程序集版本重定向到另一个程序集版本。

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

另请参阅