首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >assemblyBinding了解Newtonsoft.Json和Common.Logging连接

assemblyBinding了解Newtonsoft.Json和Common.Logging连接
EN

Stack Overflow用户
提问于 2018-07-18 04:06:26
回答 1查看 142关注 0票数 1

我通过Nuget添加到我的项目Newtonsoft.Json中。

在我这样做之后,我发现VS添加了以下部分:

代码语言:javascript
复制
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Q1:为什么要这么做?目的是什么?

Q2:为什么Common.Logging也出现在那里?我从来没有通过Nuget添加过Common.Logging。

Q3:我需要通过Nuget添加Common.Logging吗?我试过了,通过Nuget安装了Common.Logging,发现它也安装了Common.Logging.Core。但是上面的配置节没有改变!

有没有人可以用非常简单的语言向我解释一下,不用从MSDN复制粘贴,这整个马戏团是为了什么?它是如何工作的,为什么Common.Logging突然被添加到这一部分,当我只需要Newtonsoft.Json的时候,我真的需要和Common.Logging.Core一起安装它吗?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-07-18 14:28:56

Q1:为什么要这么做?目的是什么?

简单语言是,如果两个组件引用同一强名称程序集的不同版本,运行库会自动将绑定重定向添加到输出应用程序配置(app.config)文件中较新版本的程序集。

例如,您有引用库B的应用程序A,以及版本为1.0.0.0的库C。库B反过来也引用了库C,但版本1.1.0.0。现在我们有了一个冲突,因为您不能在运行时加载同一程序集的不同版本。要解决此冲突,可以使用绑定重定向。

如果您感兴趣,可以查看Redirecting Assembly Versions了解更多详细信息

Q2:为什么Common.Logging也出现在那里?我从来没有通过Nuget添加过Common.Logging。

不确定为什么它还添加了Common.Logging。它可能更多地与您的项目相关。很可能,您的项目间接引用此nuget包作为引用,或者您的项目直接引用此程序集。因为Add-BindingRedirect将检查项目输出路径中的所有程序集,并在必要时将绑定重定向添加到应用程序或web配置文件。

认证:Add-BindingRedirect

Q3:我需要通过Nuget添加Common.Logging吗?我试过了,通过Nuget安装了Common.Logging,发现它也安装了Common.Logging.Core。但是上面的配置节没有改变!

如果您可以确保只需要Newtonsoft.Json,则不需要通过Nuget添加Common.Logging。

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51389414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档