" System.Net.Http"

时间:2018-01-22 19:56:24

标签: visual-studio asp.net-core msbuild nuget

当我尝试构建我的Asp .Net Core(1.1.2)应用程序时,我收到以下警告:

  

发现不同版本的" System.Net.Http"无法解决的问题。当日志详细程度设置为详细时,这些引用冲突将在构建日志中列出。

然后变成运行时错误,所以我试图修复此警告......

我打开了Visual Studio中的详细日志记录,我在构建输出窗口中看到了这一点:

There was a conflict between "System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    "System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
    References which depend on "System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Users\mdepouw\.nuget\packages\system.net.http\4.3.1\ref\net46\System.Net.Http.dll].
        C:\Users\mdepouw\.nuget\packages\system.net.http\4.3.1\ref\net46\System.Net.Http.dll
          Project file item includes which caused reference "C:\Users\mdepouw\.nuget\packages\system.net.http\4.3.1\ref\net46\System.Net.Http.dll".
            System.Net.Http
    References which depend on "System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\System.Net.Http.dll].
        C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.applicationinsights.aspnetcore\2.1.1\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll
          Project file item includes which caused reference "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.applicationinsights.aspnetcore\2.1.1\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll".
            C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.applicationinsights.aspnetcore\2.1.1\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll
        C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Services.Common.dll
          Project file item includes which caused reference "C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Services.Common.dll".
            C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Services.Common.dll
        C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Persistence.MarkLogic.dll
          Project file item includes which caused reference "C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Persistence.MarkLogic.dll".
            C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Services.Common.dll

          ... more dlls that reference 4.1.1.2

依赖关系

nuget references screenshot

assembly references screenshot

我不明白告诉我哪个"参考"取决于System.Net.Http, Version=4.1.1.0。我正在阅读它,因为它取决于它自己。我误解了什么?

我没有通过程序集引用或Nuget引用直接引用System.Net.Http

此外,该文件位于" C:\ Users \ mdepouw.nuget \ packages \ system.net.http \ 4.3.1 \ ref \ net46 \ System.Net.Http.dll"是版本4.1.1.0

2 个答案:

答案 0 :(得分:2)

更新:原始修复程序适用于我的WebApi但不适用于查看MVC页面。我开始收到另一个运行时异常:Can not find assembly file Microsoft.CSharp.dll

我将<DependsOnNETStandard>true</DependsOnNETStandard>更改为<DependsOnNETStandard>netstandard1.6</DependsOnNETStandard>,这解决了问题。

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>
    <AssemblyName>MyProject</AssemblyName>
    <Platforms>AnyCPU;x64</Platforms>
    <DependsOnNETStandard>netstandard1.6</DependsOnNETStandard>
  </PropertyGroup>
...
</Project>

原始答案

我为this GitHub问题添加了<DependsOnNETStandard>true</DependsOnNETStandard>,我的构建警告消失了,我的运行时错误也就消失了。

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>
    <AssemblyName>MyProject</AssemblyName>
    <Platforms>AnyCPU;x64</Platforms>
    <DependsOnNETStandard>true</DependsOnNETStandard>
  </PropertyGroup>
...
</Project>

答案 1 :(得分:0)

  

我不明白告诉我哪些“参考”依赖于System.Net.Http,版本= 4.1.1.0的部分。我正在读它,因为它取决于它自己。我误解了什么?

因为Microsoft.AspNetCore中的NETStandard.Library 1.6依赖项之一在<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" /> </dependentAssembly> </assemblyBinding> 中拖拽会增加大量的System。*依赖项:

enter image description here

  

“System.Net.Http”

之间存在冲突

这是一个关于.NET核心的已知问题:

System.Net.Http package 4.3.2 - redirect to 4.2.0.0, assembly loading failure

此问题将在下一版本2.1.0中修复。

Tornhoof提供的当前解决方法:

$f_array

它使用构建扩展目录中的dll而不是Nuget中的dll。