版本冲突的Newtonsoft.Json nuget包。

3
我有一个自定义NuGet包(我们称其为Custom.SDK),它使用Newtonsoft.Json 8.0.3版本构建(该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的情况下解决这个问题?

1个回答

6

当依赖于旧版本编译的二进制文件在运行时加载新版本时,您可以使用 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正确无误。在此处阅读更多关于绑定重定向的内容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接