简体   繁体   English

System.Net.Http 的 .NET Framework 版本高于 Project

[英]Higher .NET Framework Version for System.Net.Http than Project

I have a project which references System.Net.Http 4.2.0.0 (I recently updated to the newest nuget package).我有一个引用 System.Net.Http 4.2.0.0 的项目(我最近更新到了最新的 nuget 包)。 Now I get this warning during compilation from ASPNETCOMPILER (although I use System.Net.Http in a class library project which is reference by my web project):现在我在从 ASPNETCOMPILER 编译期间收到此警告(尽管我在我的 Web 项目引用的类库项目中使用 System.Net.Http):

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: MyClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.以下程序集依赖于高于目标的 .NET Framework 版本,并且可能在运行时无法正确加载导致失败:MyClassLibrary、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null。 The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.依赖项是: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.您应该确保依赖程序集对于目标框架是正确的,或者确保您正在寻址的目标框架是依赖程序集的目标框架。 Warning in MyWebProject, ASPNETCOMPILER MyWebProject、ASPNETCOMPILER 中的警告

Both my class library and web project are using .Net 4.7.2, so no higher version to go to.我的类库和 web 项目都使用 .Net 4.7.2,所以没有更高的版本。 The web project is using MVC with System.Web.Mvc 5.2.6. Web 项目使用 MVC 和 System.Web.Mvc 5.2.6。

What causes this warning and how can I get rid of it?是什么导致了这个警告,我该如何摆脱它?

If you are using the full .NET framework, drop the Nuget reference altogether and reference System.Net.Http normally, it's already included with the full framework.如果您使用完整的 .NET 框架,请完全删除 Nuget 参考并正常参考System.Net.Http ,它已包含在完整框架中。

If that reference is the result of a third-party nuget package, please inform them that their package is broken for full framework use.如果该引用是第三方 nuget 包的结果,请通知他们他们的包已损坏以供完整框架使用。 They should add that as a reference instead of a package reference if they want to support the full framework.如果他们想支持完整的框架,他们应该将其添加为参考而不是包参考。

I used to have the same problem, but today it has downed upon me.我曾经有同样的问题,但今天它已经落在了我身上。 My code targets .NET 4.7.2, but I have also .NET 4.8 installed on my machine.我的代码面向 .NET 4.7.2,但我的机器上也安装了 .NET 4.8。 So, apparently, AspNetCompiler notices that my code takes some dependencies from the GAC, which correspond to .NET 4.8, which has a higher version that the one my code targets - 4.7.2.因此,显然,AspNetCompiler 注意到我的代码从 GAC 中获取了一些依赖项,这些依赖项对应于 .NET 4.8,它具有比我的代码目标更高的版本 - 4.7.2。 Hence the error message.因此出现错误消息。

Uninstalling .NET 4.8 removed the messages.卸载 .NET 4.8 删除了这些消息。

Your issue could have the same root cause - your local machine has .NET Framework of the higher version than the one you target.您的问题可能具有相同的根本原因 - 您的本地计算机的 .NET Framework 版本高于您的目标版本。 Either uninstall it or modify the references in the web.config that control compilation of the embedded C# code.卸载它或修改 web.config 中控制嵌入式 C# 代码编译的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM