Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

asp.net - System.Net.Http could not be resolved in the currently targeted framework .NET 4.0

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" 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:cckazorkcoderunksrcpackagesDotNetOpenAuth.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

Here is my package config:

<?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>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.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.

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...