System.Net.Http版本冲突导致生成警告 [英] System.Net.Http version conflict causing build warning

查看:54
本文介绍了System.Net.Http版本冲突导致生成警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nuget软件包Microsoft.Net.Http.2.0.20710.0引起了我的构建警告,因为它使用了System.Net.Http,Version = 2.0.0.0,它与来自另一个软件包的版本4进行了抗争.

The nuget package Microsoft.Net.Http.2.0.20710.0 is causing me a build warning because of its use of System.Net.Http, Version=2.0.0.0 which is fighting with version 4 coming from another package.

解决此问题的最佳方法是什么?软件包Microsoft.Net.Http.2.0.20710.0是否已过时,我是否应该在项目中手动引用System.Net.Http,Version = 4.0.0.0?

构建输出为:

  There was a conflict between "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
      "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
      References which depend on "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Working\MyProject\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll].
          C:\Working\MyProject\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll
            Project file item includes which caused reference "C:\Working\MyProject\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll".
              System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
      References which depend on "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll].
          C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll
            Project file item includes which caused reference "C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll".
              System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
              System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
          C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll
            Project file item includes which caused reference "C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll".
              System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
              System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
              System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
          C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.WebHost.4.0.20710.0\lib\net40\System.Web.Http.WebHost.dll
            Project file item includes which caused reference "C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.WebHost.4.0.20710.0\lib\net40\System.Web.Http.WebHost.dll".
              System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3247: Found conflicts between different versions of the same dependent assembly.

推荐答案

您可以尝试或者您可以尝试将类似以下内容添加到Web.config:

Or you can try and add something like this to your Web.config:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

这是连接错误"中的解决方法:

This is the workaround in the Connect Bug:

modify ....... ::< Reference Include ="System.Net.Http">
读取......:< Reference Include ="System.Net.Http,Version = 4.0.0.0">

modify.......: <Reference Include="System.Net.Http">
to read ......: <Reference Include="System.Net.Http, Version=4.0.0.0">

这篇关于System.Net.Http版本冲突导致生成警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆