简体   繁体   中英

Should I use the System.Net.Http Nuget Package?

.NET Framework 4.6.2 seems to have the System.Net.Http assembly/namespace built in. There is also a Nuget package of the same name that I can install.

As a general principal, can a Nuget package replace (eg update) an assembly that is included in the installed framework?

And specifically, should I use the Nuget version or the framework version of System.Net.Http?

In general, you can replace the framework library with one from NuGet. I would recommend to do it if you have a specific reason to do it. For example, if you need a bug fix, a new API or leverage performance improvements.

Specifically, with System.Net.Http it depends on your scenario. If you are making 1000 http calls a minute, use the newest from the NuGet. If you are making 2 calls an hour and you are not facing any issue, stick with the framework version. Between these two numbers, it depends.

Probably not, use the framework built-in version where possible like so:

<Reference Include="System.Net.Http" />

If something else you depend on (eg: another NuGet package) requires the NuGet version then it will get pulled in automatically, and the above reference will use whichever is available.

As said by the .NET team :

In most cases, we don't advise people use the separate System.Net.Http NuGet package anymore.

The System.Net.Http NuGet package was introduced to provide fast-track/OOB updates to the framework built-in version, particularly performance improvements. Whereas these improvements would usually be made in a new .NET Framework version, the idea here was that developers could use the NuGet package to get the newer benefits without retargeting to a newer framework.

It turns out that for various reasons this is an incredibly complicated undertaking, particularly since System.Net.Http is used by other parts of the .NET Framework itself. This caused problems when integrating into downstream applications and real production workloads. Going forward, the .NET team has decided not to ship any more OOB packages like this, although they still support and update the existing ones.

Further reading:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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