title: What is the right way to reference System.Net.Http when targeting .NET 4.7.2?
body: <p>I have a solution which contains a few web applications and so AspNetCompiler task is running during the build. Also given:</p>
  
  <ul>
  <li>VS 2017</li>
  <li>msbuild is invoked on the command line with the /err switch, i.e. warnings are promoted to errors</li>
  </ul>
  
  <p>When building our code from scratch I get the following errors (could be promoted warnings, I do not care):</p>
  
  <pre><code>ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.SystemAdmin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.SystemAdmin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: RecruitingCommon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: RecruitingCommon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.Reporting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.Reporting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.ClientAdmin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.ClientAdmin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: DataCapturing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: DataCapturing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.BusinessAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\SSOLauncher\SSOLauncher.csproj]
  ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.BusinessAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\SSOLauncher\SSOLauncher.csproj]
  </code></pre>
  
  <p>All our projects reference System.Net.Http like this:</p>
  
  <pre><code>&lt;Reference Include="System.Net.Http" /&gt;
  </code></pre>
  
  <p>No project does binding redirects for this assembly in its app.config or web.config file. </p>
  
  <p>All the projects target the .NET framework 4.7.2, but some 3rd party dependencies are .NET Standard.</p>
  
  <p>Anyway, I have searched the Internet and:</p>
  
  <ol>
  <li>Some claim that referencing System.Net.Http should only be done from NuGet, some say the opposite.</li>
  <li>Some claim that binding redirects are necessary, others - the opposite.</li>
  <li>Some say the problem was resolved with .NET Framework 4.7.2 (obviously not)</li>
  </ol>
  
  <p>I also know:</p>
  
  <ul>
  <li>The GAC contains System.Net.Http.dll with the Assembly Version of <code>4.0.0.0</code> and the File Version of <code>4.7.3190.0 built by: NET472REL1LAST_C</code>. From which I conclude it correspond to .NET 4.7.2</li>
  <li>On the other hand, during the compilation, msbuild resolves the reference to <code>c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Net.Http.dll</code>, which has the Assembly Version of <code>4.2.0.0</code> and the File Version of <code>4.7.3062.0 built by: NET472REL1</code>.</li>
  </ul>
  
  <p>Now I am confused. The file version of System.Net.Http.dll from the Reference Assemblies suggests it is older than that from the GAC, but its Assembly Version is 4.2.0.0 ? How will this dependency be resolved at run-time on a machine that has the version 4.0.0.0 in the GAC and nothing else? Checking the Reference Assemblies for older .NET versions (like 3.7.1 and below) shows System.Net.Http.dll with the Assembly Version of 4.0.0.0, so this mess is introduced with the .NET framework 4.7.2</p>
  
  <p>So, how do I make the damn thing compile cleanly? Also, I do not understand how come only AspNetCompiler complains. How does one troubleshoot it at all? The binary log does not seem to help with AspNetCompiler errors one bit.</p>