【问题标题】:Conflicting Newtonsoft.Json nuget versions.冲突的 Newtonsoft.Json nuget 版本。
【发布时间】:2016-08-22 18:46:24
【问题描述】:

我有一个使用 Newtonsoft.Json 版本 8.0.3 构建的自定义 nuget 包(我们称之为 Custom.SDK)(nuget 包含对 8.0.3 Json dll 的引用)。

我的 project.json 文件最初使用 8.0.3.0,但在将我的项目升级到 .NET Core 1.0 后,我被告知其中一个包需要 Newtonsoft.Json 9.0.0.0 - 因此我更新了我的 project.json参考 9.0.1(Custom.SDK 仍在使用 8.0.3 dll)。

现在,当我尝试构建我的项目时,我收到以下错误:

'Microsoft.AspNetCore.Mvc.Formatters.Json' with identity
Microsoft.AspNetCore.Mvc.Formatters.Json, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=adb9793829ddae60' uses 
'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 
which has a higher version than referenced assembly 
'Newtonsoft.Json' with identity 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

听起来问题是我的 Custom.SDK nuget 使用的是旧版本的 Newtonsoft.Json,而我的 project.json 引用了新版本(我需要升级到 .NET Core 1.0)。

是否可以在不更新 Custom.SDK 中的 JSON dll 的情况下解决这个问题?

【问题讨论】:

    标签: c# json visual-studio nuget


    【解决方案1】:

    使用旧版本编译的依赖二进制的典型情况,当在运行时加载新的时,您应该能够在App.config中使用BindingRedirect解决,如下所示:

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
                <bindingRedirect oldVersion="8.0.0.0" newVersion="9.0.0.0" />
            </dependentAssembly>        
        </assemblyBinding>
    </runtime>
    

    这将确保在运行时它会请求版本 8.0.0.0,它会自动重定向到已加载的 9.0.0.0,请确保版本号和其他信息如 Public Key token 是正确的,阅读更多关于 @ 987654321@这里

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-09
      • 2019-01-10
      • 2018-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      相关资源
      最近更新 更多