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

Dav*_*New 19 .net c# 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.
Run Code Online (Sandbox Code Playgroud)

这是web.config dependentAssembly我的Api.dll项目中此程序集的条目:

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

已安装的Json.NET NuGet包的实际版本是6.0.1:

在此输入图像描述

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

在此输入图像描述

System.Net.Http.Formatting引用的版本是5.1.0.0.

在构建定义中启用了NuGet还原,并且我的本地副本上没有这些错误,仅在TFS中.

有人能够发现可能出现的问题吗?

我想这可能是由于dependentAssembly进入,但我不能让它工作.

小智 15

如果您已经清理了项目文件,包文件和引用,并且所有版本都是Newtonsoft的正确和最新版本,它可能是一个依赖于早期版本的Newtonsoft.Json的.Net dll.在我的例子中,它是System.Net.Http.Formatting,版本= 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>
Run Code Online (Sandbox Code Playgroud)

在针对WebAPI项目运行测试项目时,由于Newtonsoft.Json版本在4.5.0.0和6.0.1.0之间不匹配,因此从WebAPI抛出了FileNotFound异常.将语句添加到调用测试项目的app.config 修复了该问题.


Dav*_*New 14

这个问题出人意料.

修复是在每个相关<PropertyGroup>部分下的项目文件中包含以下行:

<CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
Run Code Online (Sandbox Code Playgroud)

要编辑项目文件,请右键单击该项目,然后单击" 卸载项目".现在右键单击卸载的项目,然后选择Edit MyProject.csproj

  • 我在我们的测试服务器上遇到了同样的问题,但它在我的开发机上工作正常,<dependentAssembly> .. <bindingRedirect>对我不起作用.还试过StrongNameIgnoringVersion,但没有运气.这花费了我几天.还有其他想法吗? (2认同)