question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature]: Use reference to System.Net.Http using framework `Reference` instead of PackageReference

See original GitHub issue

Background and motivation

I hope this is the correct place to raise this.

Currently for .net47 target you are adding reference to System.Net.Http as package dependency:

 <ItemGroup Condition="'$(TargetFramework)' == 'net47'">
    <PackageReference Include="System.Net.Http" Version="4.3.4" />
  </ItemGroup>

According to this issue dot net team advise adding System.Net.Http standard framework reference instead. Just quoting them:

if you’re building a .NET Framework 4.7.2 class library, then you could just add a normal Framework reference to System.Net.Http.

In most cases, we don’t advise people use the separate System.Net.Http NuGet package anymore. See https://github.com/dotnet/runtime/issues/18280 and https://github.com/dotnet/runtime/issues/20777.

The main reason why I am suggesting this change is that VisualStudio resolve 4.7.2 project dependency to System.Net.Http and all its System dependencies by adding references to .net framework installed on local machine instead of project nuget. I think this issue has been raise in multiple place e.g. Broken System.Net.Http 4.1.1-4.3.0 post-mortem . It can also be problematic when you have reference to same assembly with both a single name reference and a package reference. For more details please take a look on Single-name references are removed by the SDK when targeting .NET Framework 4.7.2 and referencing a package with the same assembly

Alternative Concerns

Could you consider changing above to something like:

<ItemGroup Condition=" '$(TargetFramework)' == 'net47' ">
    <Reference Include="System.Net.Http" />
</ItemGroup>

It looks like another few other projects decide to follow this advise e.g. IdentityModel, Microsoft Graph

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
jacekmlynekcommented, Feb 6, 2023

sorry, I wasn’t able to answer during the weekend.

@dennisdoomen @AArnott I have take a look at #2122 - looks sensible to me and what is more import, the attached pre-release version solved my issues.

To be honest I do not fully understand why msbuild resolved System.Net.Http reference in this way and why in some projects behaviour is different The only thing that I was able to find suggest that this may be related to bindings in config

I agree that it is insane coincidence 😃

1reaction
IT-VBFKcommented, Feb 10, 2023

Fixed with 97cf195?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio forces use System.Net.Http in Reference ...
I reference System.Net.Http as a nuget package in my project, the references are correct in packages.config and .csproj file, but in Visual ...
Read more >
Migrate from packages.config to PackageReference
Manage all project dependencies in one place: Just like project to project references and assembly references, NuGet package references ...
Read more >
System.Net.Http is driving me insane. : r/csharp
There are references to assemblies in the .csproj, the packages config, and the web.config file(including assembly redirects here). I'm very ...
Read more >
How to resolve .NET reference and NuGet package version ...
Here's another scenario: We reference project A with NuGet which references System.Net.Http v4.5. We also reference project B with NuGet ...
Read more >
System.Net.Http 4.3.4
Provides a programming interface for modern HTTP applications, including HTTP client components that allow applications to consume web services ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found