System.Net.Http 在当前目标框架 .NET 4.0 中无法解析

System.Net.Http could not be resolved in the currently targeted framework .NET 4.0(System.Net.Http 在当前目标框架 .NET 4.0 中无法解析)
本文介绍了System.Net.Http 在当前目标框架 .NET 4.0 中无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

将解决方案从 Visual Studio 2010 移至 2012 后出现严重错误.构建正常,一切正常,本地主机运行良好.我有一个需要 .NET 4.5 的新 MVC4 项目,所以我在构建服务器上安装了 4.5 框架.构建很好,但 MSBuild 无法将 DotNetOpenAuth.Core.dll 从其包位置复制到 Bin 目录.问题在于,尽管特定项目以 4.0 框架为目标,但我相信 MSBuild 正在检查对 .NET 4.5 框架 System.Net.Http 程序集的依赖关系,作为其 CoreBuild 的一部分.

Got a nasty error after moving a solution from Visual Studio 2010 to 2012. Build is fine and everything works perfect localhost. I have one new MVC4 project that requires .NET 4.5 so I installed the 4.5 framework on the build server. The build is good but MSBuild is failing to copy DotNetOpenAuth.Core.dll from its package location to the Bin dir. The issue is because, though the particular project targets the 4.0 framework, I believe MSBuild is checking the dependency against .NET 4.5 framework System.Net.Http assembly as part of its CoreBuild.

warning code="MSB3268" 主要参考 packagesDotNetOpenAuth.Core.4.3.0.13117lib et40-fullDotNetOpenAuth.Core.dll" 无法解析,因为它间接依赖于框架程序集"System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 在当前目标框架中无法解决.".NETFramework,Version=v4.0".要解决此问题,请删除参考c:cckazorkcode runksrcpackagesDotNetOpenAuth.Core.4.3.0.13117lib et40-fullDotNetOpenAuth.Core.dll"或将您的应用程序重新定位到包含System.Net.Http,版本=2.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a

warning code="MSB3268" The primary reference packagesDotNetOpenAuth.Core.4.3.0.13117lib et40-fullDotNetOpenAuth.Core.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "c:cckazorkcode runksrcpackagesDotNetOpenAuth.Core.4.3.0.13117lib et40-fullDotNetOpenAuth.Core.dll" or retarget your application to a framework version which contains "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

这是我的包配置:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="ChardinJs" version="1.0.3" targetFramework="net40" />
  <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
  <package id="DotNetOpenAuth.AspNet" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.Core" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.OAuth.Consumer" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.OAuth.Core" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.OpenId.Core" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.OpenId.RelyingParty" version="4.3.0.13117" targetFramework="net40" />
  <package id="EntityFramework" version="5.0.0" targetFramework="net40" />
  <package id="flexigrid" version="1.1.0" targetFramework="net40" />
  <package id="jQuery" version="1.9.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.FriendlyUrls.Core" version="1.0.0" targetFramework="net40" />
  <package id="Microsoft.AspNet.Membership.OpenAuth" version="1.0.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Core" version="1.1.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.JS" version="1.1.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Owin" version="1.1.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.SystemWeb" version="1.1.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net40" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="1.0.1" targetFramework="net40" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
  <package id="Newtonsoft.Json" version="5.0.5" targetFramework="net40" />
  <package id="Owin" version="1.0" targetFramework="net40" />
  <package id="PayPalCoreSDK" version="1.1.1" targetFramework="net40" />
  <package id="PayPalMerchantSDK" version="2.3.98" targetFramework="net40" />
  <package id="Select2.js" version="3.3.2" targetFramework="net40" />
  <package id="toastr" version="1.2.2" targetFramework="net40" />
  <package id="Twitter.Bootstrap" version="2.3.2" targetFramework="net40" />
  <package id="WebGrease" version="1.3.0" targetFramework="net40" />
</packages>

我引用了 System.Net.Http 并将其复制到 bin.有问题的项目针对 4.0 框架.我的版本 System.Net.Http 是针对 4.0 框架的.

I have System.Net.Http referenced and it is copied to the bin. The project in question is targeting the 4.0 framework. My version System.Net.Http is for the 4.0 framework.

推荐答案

所以即使我通过安装 DotNetOpenAuth 包时添加的 Nuget 包复制 System.Net.Http .NET 4.0,我的构建服务器上的 MsBuild 是检查 DotNetOpenAuth.Core 依赖项并检查机器上安装的 .NET 程序集,而不是复制到 Bin 的内容.就我而言:

So even though I was copying System.Net.Http .NET 4.0 via the Nuget package that is added when installed the DotNetOpenAuth packages, MsBuild on my build server was checking the DotNetOpenAuth.Core dependency and checking against .NET assemblies installed on the machine not what was being copied to the Bin. In my case:

C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.0

我的中没有 System.Net.Http 程序集

And there was no System.Net.Http assembly in my

C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.0

目录,所以我相信 MsBuild 试图在我的机器上查看新安装的 .NET 4.5 程序集..AssembliesMicrosoftFramework.NETFrameworkv4.5 那里有一个 System.Net.Http.dll 并且这就是为什么,我没有收到关于 .NET 4.0 目标的 System.Net.Http.dll 不存在的彻底错误,而是收到关于 DotNetOpenAuth.Core.dll 对 System.Net.Http 的依赖的警告,可以找到但不适用于项目所针对的 4.0 框架.

directory so I believe MsBuild attempted to look in the newly installed .NET 4.5 assemblies, on my machine..AssembliesMicrosoftFramework.NETFrameworkv4.5 where there is a System.Net.Http.dll and that is why, instead of getting an outright error that System.Net.Http.dll for .NET 4.0 targets does not exist, I got a warning about DotNetOpenAuth.Core.dll's dependency on System.Net.Http, which can be found but is not for the 4.0 framework as the project was targeting.

我只是将 System.Net.Http .NET 4.0 DLL 从包中复制到

I simply copied System.Net.Http .NET 4.0 DLL from the package to

C:Program Files (x86)参考程序集MicrosoftFramework.NETFrameworkv4.0

C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.0

在我的构建服务器上,MsBuild 能够与正确版本的 System.Net.Htpp 进行比较,以进行 4.0 .NET 框架依赖性检查.

on my build server and MsBuild was able to compare to the correct version System.Net.Htpp for 4.0 .NET framework dependency check.

这篇关于System.Net.Http 在当前目标框架 .NET 4.0 中无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

MSBuild cannot find a reference(MSBuild 找不到参考)
The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
quot;File has a different computed hash than specified in manifestquot; error when signing the EXE(“文件的计算哈希值与清单中指定的不同签署EXE时出错)
Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?(良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 MSBuild 脚本?)
Run an MSBuild target only if project is actually built(仅在实际构建项目时运行 MSBuild 目标)
MS-Build BeforeBuild not firing(MS-Build BeforeBuild 未触发)