我的构建服务器 (TFS/Visual Studio Online) 上出现以下错误:
CA0055 : Could not load C:\a\Binaries\Api.dll. The following error was encountered while reading module 'System.Net.Http.Formatting': Assembly reference cannot be resolved: Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed.
CA0058 : The referenced assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' could not be found. This assembly is required for analysis and was referenced by: C:\a\Binaries\Api.dll, C:\a\Sources\MyLocation\packages\Microsoft.AspNet.WebApi.Client.5.1.1\lib\net45\System.Net.Http.Formatting.dll.
这是我的 Api.dll 项目中用于此程序集的 web.config
dependentAssembly
条目:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
实际安装的Json.NET NuGet包的版本是6.0.1:
在查看项目引用时,我将 Newtonsoft.Json 设置为 6.0.0.0:
引用资料中System.Net.Http.Formatting
的版本是5.1.0.0。
构建定义中启用了 NuGet 恢复,我的本地副本上没有这些错误,只有 TFS 中才有。
有人能找出问题所在吗?
我认为这可能是由于 dependentAssembly
条目造成的,但我无法让它工作。
最佳答案
如果您已经清理了项目文件、包文件和引用,并且所有版本都是正确的最新版本的 Newtonsoft,则它可能是一个 .Net dll,它依赖于早期版本的 Newtonsoft.Json。在我的例子中,它是 System.Net.Http.Formatting, Version=4.0.0.0:
尝试将以下内容添加到调用 项目的 *.config 中:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
针对 WebAPI 项目运行测试项目时,由于 4.5.0.0 和 6.0.1.0 之间的 Newtonsoft.Json 版本不匹配,WebAPI 抛出了 FileNotFound 异常。将语句添加到 calling 测试项目的 app.config 解决了这个问题。
关于c# - 无法解决程序集引用 - dependentAssembly 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21876887/