是否有可能解决这种装配不匹配的情况?还是这无法解决?

时间:2018-07-24 14:01:44

标签: c# .net nuget .net-assembly versioning

我要在程序集中使用

SomeLibrary.dll-> Newtonsoft.Json, Version 10.0.0.0

我通过路径引用SomeLibrary.dll的位置。那我也有

Microsoft.NET.Sdk.Functions-> Newtonsoft.Json, Version 9.0.0.1

两者都被Nuget引用。这样做会导致版本不匹配

JsonConvert.DeserializeObject<SomeTypeFromSomeLibrary>(json)

对此我能做什么? :(

1 个答案:

答案 0 :(得分:4)

通常用binding redirect解决此问题。

对于JSON.NET,它可能看起来像这样:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
相关问题