【问题标题】:assemblyBinding understanding Newtonsoft.Json and Common.Logging connectionassemblyBinding 理解 Newtonsoft.Json 和 Common.Logging 连接
【发布时间】:2018-12-25 15:06:59
【问题描述】:

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

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

  <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 通过 Nuget 安装 Common.Logging,发现它也安装了 Common.Logging.Core。但是上面的配置部分没有改变!

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

谢谢。

【问题讨论】:

  • 这个问题有什么更新吗?你解决了这个问题吗?如果没有,请告诉我有关此问题的最新信息吗?

标签: visual-studio web-config nuget app-config


【解决方案1】:

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

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

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

有兴趣的可以看Redirecting Assembly Versions了解更多详情

Q2:为什么Common.Logging也会出现在那里?我从来没有添加 Common. 通过 Nuget 进行日志记录。

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

认证:Add-BindingRedirect

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

如果你能确定你只需要Newtonsoft.Json,你就不需要通过Nuget添加Common.Logging。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-01
    • 2011-01-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 2013-01-06
    相关资源
    最近更新 更多