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 \packages\DotNetOpenAuth.Core.4.3.0.13117\lib\net40-full\DotNetOpenAuth.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:\cc\kazork\code\trunk\src\packages\DotNetOpenAuth.Core.4.3.0.13117\lib\net40-full\DotNetOpenAuth.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.
Http Namespace | Microsoft Learn. This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Open Visual Studio Developer Command Prompt or Visual Studio Developer PowerShell and enter clrver . For .NET Framework 4.5 and later versions, don't use the Environment.Version property to detect the version of the CLR.
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 Assemblies\Microsoft\Framework\.NETFramework\v4.0
And there was no System.Net.Http assembly in my
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
directory so I believe MsBuild attempted to look in the newly installed .NET 4.5 assemblies, on my machine..\Assemblies\Microsoft\Framework.NETFramework\v4.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 Assemblies\Microsoft\Framework\.NETFramework\v4.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.
If this fails, you may also need to apply the .Net v4.5.1 dev pack as this supports multiple targeting. I had 4.5.1 installed and the assemblies copied and still had this error. Installing the dev pack from http://www.microsoft.com/en-us/download/details.aspx?id=40772 fixed this issue and now builds under server 2012 r2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With