Search code examples
visual-studiohttpnugetenterprise-librarysystem.net

VS Enterprise .NET Build Extensions version of System.Net.Http overrides intended 4.3.3 nuget version


I'm currently using Visual Studio 2017 Enterprise edition. The issue I'm running into is that every time I install the latest System.Net.Http nuget package (4.3.3) into a project, the System.Net.Http reference seems to prefer to point to the VS Enterprise extensions version of System.Net.Http:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net471\lib\System.Net.Http.ddl

I tried everything to force it to use the nuget version including binding redirects:

  <dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
  </dependentAssembly>

and setting the "HintPath" in the .csproj file:

<Reference Include="System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll</HintPath>
</Reference>

But it still just keeps snapping back to the above VS Enterprise extensions version. I need to be able to use the nuget version of System.Net.Http dll because I have another library (Serilog) that depends on it.

Two questions: (1) Why does this happen? (2) How do I force it to ignore the VS Enterprise version of it?


Solution

  • This looks like some problem with referencing packages in .net framework 4.6:

    If you're building a .NET Framework 4.6.x app, you should just use standard references to System.Net.Http and not bring in any Nuget package for System.Net.Http.

    You could try to upgrade .net framework in your project to the latest release. More information about this issue: System.Net.Http v4.2.0.0 being copied/loaded from MSBuild tooling