冲突的Newtonsoft.Json nuget版本.

Rok*_*545 3 c# json visual-studio nuget

我有一个使用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 - 因此我将pr​​oject.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'
Run Code Online (Sandbox Code Playgroud)

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

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

Mri*_*boj 6

使用旧版本编译的从属二进制文件的典型情况,在运行时加载新版本时,您应该能够使用BindingRedirectin 解析App.config,如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

这样可以确保在运行时它会请求版本8.0.0.0,它会自动重定向到已加载的9.0.0.0,请确保版本号和其他信息一样Public Key token正确,请在此处阅读有关Binding Redirect的更多信息