System.Net.Http 的 VS Enterprise .NET Build Extensions 版本覆盖预期的 4.3.3 nuget 版本

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

我目前使用的是 Visual Studio 2017 企业版。我 运行 遇到的问题是每次我将最新的 System.Net.Http nuget 包 (4.3.3) 安装到项目中时,System.Net.Http 引用似乎更喜欢指向 VS System.Net.Http 的企业扩展版本:

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

我尝试了所有方法来强制它使用 nuget 版本,包括绑定重定向:

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

并在 .csproj 文件中设置 "HintPath":

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

但它仍然只是快速回到上面的 VS 企业扩展版本。我需要能够使用 System.Net.Http dll 的 nuget 版本,因为我有另一个依赖它的库 (Serilog)。

两个问题:(1)为什么会这样? (2) 如何强制忽略它的 VS Enterprise 版本?

这看起来像是在 .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.

您可以尝试将项目中的.net framework 升级到最新版本。有关此问题的更多信息:System.Net.Http v4.2.0.0 being copied/loaded from MSBuild tooling