Web Api:找不到System.Net.Http版本2.0.0.0

CDu*_*z31 6 system.net .net-assembly nuget-package asp.net-web-api system.net.httpwebrequest

当我为WebApi安装NuGet包时,它给了我1.0.0.0版的System.Net.Http,但它引用了版本2.

我似乎无法找到我的生活版本2.当我下载.net 4.5时,我得到System.Net.Http版本4.0.315.x,但我不能使用它,因为Web Api程序集引用版本2.0.0.0.

有谁知道我在哪里可以找到这个版本2.0.0.0?我已经尝试过NuGet包管理器,mvc4,.net 4.5,没有什么能给我版本2.

提前致谢.

tug*_*erk 12

<system.web>节点下的Web.config文件中添加以下配置(假设您的应用程序在.NET 4.5上运行,targetFramework属性设置为4.5):

<compilation targetFramework="4.5">
  <assemblies>
    <add assembly="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </assemblies>
</compilation>
Run Code Online (Sandbox Code Playgroud)

还要在<configuration>节点下的根级别添加以下内容:

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

这应该可以解决您的问题.