.NET Visual Studio 使用来自 NuGet 的引用导致无法加载文件或程序集
.NET Visual Studio using reference from NuGet causes Could not load file or assembly
我在使用 NuGet 时遇到引用(库)依赖性问题,这让我很烦,请找到我的项目及其关系如下:
Utils
项目依赖于Newtonsoft.Json
Project A
取决于 Utils
项目,该项目是 .NET 运行时 2.0 的目标
Project B
取决于 Utils
项目,该项目是 .NET runtime 4.0 的目标
Project C
取决于 Utils
项目,该项目是 .NET runtime 4.5 的目标
我决定 Utils
项目应该使用 Newtonsoft.Json
的最低要求版本,即 6.0.4
用于 .NET 2.0
我认为消费者可以自动覆盖它但是我错了
Project A
、Project B
和 Project C
将针对不同的 .NET 运行时使用不同版本的 Newtonsoft.Json
。现在,每当程序进入 Utils
内的代码以使用 Newtonsoft.Json
的任何引用时,它都会抛出异常 Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.
有没有人知道 Google 中的关键字应该是什么或者更好的解决方案?感谢您的时间和关注。
我花了几个小时终于解决了这个问题。
诀窍是将以下块添加到 app.config
/web.config
中,使程序将引用从旧版本库重定向到新版本。 (其中值10.0.0.0
应该是较新库的版本号)
<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>
我在使用 NuGet 时遇到引用(库)依赖性问题,这让我很烦,请找到我的项目及其关系如下:
Utils
项目依赖于Newtonsoft.Json
Project A
取决于Utils
项目,该项目是 .NET 运行时 2.0 的目标
Project B
取决于Utils
项目,该项目是 .NET runtime 4.0 的目标
Project C
取决于Utils
项目,该项目是 .NET runtime 4.5 的目标
我决定 Utils
项目应该使用 Newtonsoft.Json
的最低要求版本,即 6.0.4
用于 .NET 2.0
我认为消费者可以自动覆盖它但是我错了
Project A
、Project B
和 Project C
将针对不同的 .NET 运行时使用不同版本的 Newtonsoft.Json
。现在,每当程序进入 Utils
内的代码以使用 Newtonsoft.Json
的任何引用时,它都会抛出异常 Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.
有没有人知道 Google 中的关键字应该是什么或者更好的解决方案?感谢您的时间和关注。
我花了几个小时终于解决了这个问题。
诀窍是将以下块添加到 app.config
/web.config
中,使程序将引用从旧版本库重定向到新版本。 (其中值10.0.0.0
应该是较新库的版本号)
<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>