简体   繁体   English

ASP.NET Web API项目中的System.Data.Common,System.Net.Http框架与Nuget程序集

[英]System.Data.Common, System.Net.Http Framework vs Nuget assembly in ASP.NET Web API project

I am really confused about these two libraries that are included in the .NET Framework but are also available on Nuget. 我对.NET Framework中包含但在Nuget上可用的这两个库感到非常困惑。 My instinct is to use the Nuget one as I would be getting more frequent updates etc. However Visual Studio even though I have referenced the one from nuget the msbuild uses one from .NET framework located at: 我的本能是使用Nuget,因为我会得到更频繁的更新等。但是,即使我引用了nuget中的一个,Visual Studio还是msbuild使用.NET框架中的一个:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib

One workaround I found on github was to remove those libraries from the msbuild folder. 我在github上发现的一种解决方法是从msbuild文件夹中删除这些库。 But anytime I update VS Studio it brings them back there. 但是,每当我更新VS Studio时,都会将它们带回那里。 Also the nuget package introduced some binding redirects. nuget包还引入了一些绑定重定向。 I can't count how many times the build goes fine and then Xth build gives an error that just makes no sense in regards to those assemblies. 我无法确定构建可以进行多少次,然后Xth构建会给出一个错误,这些错误对于这些程序集而言毫无意义。

Do you recommend removing the nuget packages and use the ones contained in the framework? 您是否建议删除nuget软件包并使用框架中包含的软件包?

I got an answer from Jose Perez Rodriguez on Visual Studio Forum which explains it quite nicely: 我在Visual Studio论坛上得到了Jose Perez Rodriguez的回答 ,解释得很好:

Hello Jakub, and thanks for posting your question. 您好雅库布,并感谢您发布您的问题。 Sorry it took us so long to respond. 抱歉,我们花了很长时间才回应。 First of all, I do agree with you that this space in general is a bit confusing, but here is a TL;DR explanation of the issue. 首先,我确实同意您的看法,这个空间通常有点令人困惑,但这是有关此问题的TL; DR解释。 System.Net.Http and System.Data.Common packages to get updated more frequently, but only for the .NET Core implementation, not for .NET Framework which is what you are targetting. System.Net.Http和System.Data.Common软件包可以更频繁地进行更新,但仅针对.NET Core实现,而不针对您所针对的.NET Framework。 .NET Framework actually already has a version of these two assemblies installed in the GAC, but it is not the newest version (at least that is the case for frameworks < 4.7.2), and if your application has any dependency that is targeting .NET Standard 1.4+, then you will most likely need the very latest version of these assemblies in order for your app to work correctly at runtime. .NET Framework实际上已经在GAC中安装了这两个程序集的版本,但是它不是最新版本(至少是<4.7.2的框架是这种情况),并且您的应用程序是否具有针对性的依赖关系。 NET Standard 1.4+,那么您很可能需要这些程序集的最新版本,才能使您的应用程序在运行时正确运行。 The latest version for .NET Framework is not the one in the GAC nor the one in the packages as I've said before, but instead the one found in the MSBuild Extensions folder that you found. .NET Framework的最新版本不是GAC中的版本,也不是我之前所说的软件包中的版本,而是在您找到的MSBuild Extensions文件夹中找到的最新版本。 Those versions are really the latest versions for .NET Framework, so when our build detects that you will need them, we inject them into your bin folder and we reference those in order to be able to not hit any runtime issues. 这些版本实际上是.NET Framework的最新版本,因此当我们的版本检测到您将需要它们时,我们会将它们注入到bin文件夹中,并引用它们以免遇到任何运行时问题。

So all in all, the conclusion is that whichever workaround you found saying to delete those files from that directory is incorrect, and should never really be done as that may cause your app to have runtime issues. 因此,总而言之,结论是,无论您发现说从该目录中删除这些文件的任何解决方法都是不正确的,并且绝对不应这样做,因为这可能会导致您的应用程序出现运行时问题。 In order to let your app work properly, remove the binding redirects that were added automatically by NuGet when you installed the System.Net.Http and the Data.Common packages, and make sure you turn on AutoGenerateBindingRedirects. 为了使您的应用程序正常工作,请删除在安装System.Net.Http和Data.Common程序包时NuGet自动添加的绑定重定向,并确保打开AutoGenerateBindingRedirects。 After taking those steps (and making sure that you restore that msbuild extensions folder since you said you deleted some files from it) your app in the end should have a copy of these assemblies in the bin folder with the latest version of them, and it should also have an app config with the right binding redirects generated at build time. 采取这些步骤(并确保已从您说的从其中删除了一些文件以来,确保还原了msbuild extensions文件夹)之后,您的应用最后应在bin文件夹中包含这些程序集的副本,并包含它们的最新版本。还应具有在配置时生成具有正确绑定重定向的应用程序配置。

We will do a better job of explaining this behavior in github, since a lot of people are confused by this behavior. 我们将在github中更好地解释这种行为,因为很多人对此行为感到困惑。 I hope this answers your question, but if not, please feel free to ask any follow up questions you may have. 希望这能回答您的问题,但如果不能,请随时提出任何后续问题。

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

相关问题 应用程序无法在asp.net Web窗体中加载程序集&#39;System.Net.Http&#39; - application is not able to load assembly 'System.Net.Http' in asp.net webforms ASP.NET 5控制台应用程序dnxcore50缺少`System.Net.Http&#39;程序集参考? - ASP.NET 5 Console Application dnxcore50 missing `System.Net.Http' assembly reference? System.Net.Http 的 .NET Framework 版本高于 Project - Higher .NET Framework Version for System.Net.Http than Project 在VS 2012项目中启用System.Net.Http - Enabling System.Net.Http within VS 2012 Project 在网站项目中找不到System.Net.Http - Unable to find System.Net.Http in web site project 参考问题system.net.http nuget包4.3.1可能无法加载system.net.http 4.1.1 - reference problems system.net.http nuget package 4.3.1 coul not load system.net.http 4.1.1 无法加载文件或程序集&#39;System.Net.Http,Version = 4.1.0.0 .net framework 4.6 .net standard 1.3 - Could not load file or assembly 'System.Net.Http, Version=4.1.0.0 .net framework 4.6 .net standard 1.3 Visual Studio 强制在参考程序集中使用 System.Net.Http 而不是 Nuget 中指定的那个 - Visual Studio forces use System.Net.Http in Reference Assembly rather than the one specified in Nuget System.Net.Http 缺少组件,.NET 4.7.2 和 SharePoint CSOM - System.Net.Http missing assembly, .NET 4.7.2 and SharePoint CSOM Nuget错误:无法添加对System.Net.Http的引用 - Nuget Error: Failed to add reference to System.Net.Http
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM