添加Microsoft.Net.Http包遇依赖问题求助(.NET Standard/VS2017)
Hey there! As a fellow Xamarin.Forms developer, I’ve run into this exact issue before—let’s break down how to fix it quickly.
Why You’re Seeing This Error
The Microsoft.Net.Http NuGet package is an older, .NET Framework-specific package that doesn’t properly target .NET Standard 2.0. When you try to install it into your .NET Standard project, NuGet falls back to using the .NET Framework 4.6.1 version, which causes the dependency mismatch you’re seeing.
The Correct Solution
Good news: .NET Standard 2.0 already includes the System.Net.Http namespace natively—you don’t need the Microsoft.Net.Http package at all! Here’s what to do:
Uninstall the problematic package (if you already installed it):
- Right-click your project in Solution Explorer → Manage NuGet Packages
- Go to the "Installed" tab, find
Microsoft.Net.Http, click Uninstall, and confirm the changes.
Use the built-in
System.Net.Http:- Simply add this using statement to your code files where you need HTTP functionality:
using System.Net.Http; - Visual Studio should automatically reference the correct assembly for .NET Standard 2.0. If not, you can manually add it:
- Right-click your project → Add → Reference
- Under "Assemblies", locate and check
System.Net.Http, then click OK.
- Simply add this using statement to your code files where you need HTTP functionality:
If You Need Additional HTTP Features
For most basic HTTP operations (like making GET/POST requests with HttpClient), the built-in System.Net.Http is sufficient. If you require specific extensions or newer features, install the official System.Net.Http NuGet package instead—make sure to pick a version that supports .NET Standard 2.0 (versions 4.3.3 and above work perfectly).
Quick Tip for VS2017
Ensure your Visual Studio 2017 is updated to the latest patch version (at least 15.9.x). Older versions of VS2017 had minor compatibility quirks with .NET Standard 2.0, and updating will resolve many of these issues.
内容的提问来源于stack exchange,提问作者Md Tayeb Himel

