Multi-Version .NET Targeting and the Subsequent System.Net.Http Issue[s]

When developing an library that targets multiple .NET versions, you most likely start-off with a .NET Standard library and change the CSPROJ file to include other .NET versions.

When you do this, Visual Studio and/or NuGet have a hard time deciphering just which verison of the System.Net.Http assembly to use. You’ll see this manifest as the below exception:

CS0234 C# The type or namespace name ‘Http’ does not exist in the namespace ‘System.Net’ (are you missing an assembly reference?)

The easiest way to fix/resolve this, despite what other links on the internet tell you is a plausible route to use, is to tell Visual Studio which version of the .NET Framework assembly that you want to use (as that is the assembly that it cannot resolve).

You can do this by adding the below into your Item Group:

<PackageReference Include=”System.Net.Http” Version=”4.3.0″/>

Save the CSPROJ file and, after a few seconds, Visual Studio should now be able to resolve the assembly and the exception[s] should go away.

Thanks for coming to this TEDPost and happy dev’ing!