c# - 无法解决程序集引用 - dependentAssembly 问题?

标签 c# .net tfs web-config nuget

我的构建服务器 (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:

enter image description here

在查看项目引用时,我将 Newtonsoft.Json 设置为 6.0.0.0:

enter image description here

引用资料中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:

enter image description here

尝试将以下内容添加到调用 项目的 *.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/

相关文章:

tfs - 如何从我的 TFS 服务器列表中删除 tfspreview?

c# - Word 2016自动生成 "error: 80080005 Server execution failed"

c# - If/Else OR "? :"(条件)不工作

c# - 制作自动运行应用程序的最佳解决方案?

.net - 使用网页创建桌面快捷方式

visual-studio-2012 - 使用 TFS 2012 RTM 更改 Scrum 模板的默认休息日

c# - DropDownList 验证 - 问题

c# - 使用 FlurlClient 的自定义 HttpClientHandler 不使用 ClientCertificate

java - 通过java代码自动化在Outlook中添加约会事件

c# - 无法将类型为 'System.__ComObject' 的 Com 对象转换为接口(interface)类型 VsRunningDocumentTable4