C# web.config>configuration>runtime>assemblyBinding 中生成的条目的含义/原因是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15056499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 13:54:19  来源:igfitidea点击:

What is the meaning/reason for the generated entries in web.config>configuration>runtime>assemblyBinding?

c#asp.netweb-configassemblybinding

提问by Aaron Anodide

I've noticed this section in my web.config files for a while and I'm now trying to reason out what exactly the purpose is:

我已经注意到我的 web.config 文件中的这一部分有一段时间了,我现在正试图弄清楚到底是什么目的:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

So, the first entry seems to say:

所以,第一个条目似乎说:

System.Web.Helpers is the name of a dependent assembly with a public key token of 31bf3856ad364e35. Redirect version 1.0.0.0 through 2.0.0.0 to version 2.0.0.0.

System.Web.Helpers 是具有公钥标记的依赖程序集的名称31bf3856ad364e35。将 1.0.0.0 版到 2.0.0.0 版重定向到 2.0.0.0 版。

My best guess is that it means any code executing in the context of the ASP.NET run time that depends on an assembly with the specified name which also has a version in the specified range executes as if it were compiled with the specified version with the specified public key.

我最好的猜测是,这意味着在 ASP.NET 运行时上下文中执行的任何代码都依赖于具有指定名称的程序集,该程序集也具有指定范围内的版本,就像它是使用指定版本编译的一样执行指定的公钥。

Does this mean if I have a web project that depends on a class library and that class library has a reference to an older version of the assembly which has a a bindingRedirect, that the code will execute as if it were compiled against the newer version?

这是否意味着如果我有一个依赖于类库的 Web 项目,并且该类库引用了具有 bindingRedirect 的旧版本程序集,那么代码将像针对新版本编译一样执行?

采纳答案by jbl

Does this mean if I have a web project that depends on a class library and that class library has a reference to an older version of the assembly which has a a bindingRedirect, that the code will execute as if it were compiled against the newer version?

这是否意味着如果我有一个依赖于类库的 Web 项目,并且该类库引用了具有 bindingRedirect 的旧版本程序集,那么代码将像针对新版本编译一样执行?

You have it right (I would just say "...the code will execute as if it were referencing the newer version"), see http://msdn.microsoft.com/en-us/library/7wd6ex19%28v=vs.110%29.aspx

你说得对(我只想说“......代码将像引用较新版本一样执行”),请参阅http://msdn.microsoft.com/en-us/library/7wd6ex19%28v=vs .110%29.aspx

"When you build a .NET Framework application against a specific version of a strong-named assembly, the application uses that version of the assembly at run time. However, sometimes you might want the application to run against a newer version of an assembly."

“当您针对强命名程序集的特定版本构建 .NET Framework 应用程序时,该应用程序在运行时使用该版本的程序集。但是,有时您可能希望应用程序针对较新版本的程序集运行。 ”