-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CS0234 'Http' does not exist in the namespace 'System.Net' when targeting .NET Fx 4.x with implicit usings #24146
Comments
(As a workaround, you can put |
The default list of usings are primarily tailored for .NET 6 and newer apps, and aren't enabled by default. You can use the |
|
This comment has been minimized.
This comment has been minimized.
Which node to put |
I solved it by installing the nuget package "System.Net.Http" |
An automatic workaround for the whole solution is to put near <Project>
<!-- Workaround for https://github.com/dotnet/sdk/issues/24146 -->
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">
<Using Remove="System.Net.Http" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '4.0')) ">
<Using Remove="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '3.5')) ">
<Using Remove="System.Linq" />
</ItemGroup>
</Project> |
Put "near" it? What does that mean? Do you mean put that content in the .sln file? |
A It isn't really related to the solution file, though. The important thing is that |
This issue has been fixed by #32630 |
Describe the bug
C# 10 introduces global usings. The .NET 6 SDK ships with a default template for implicit usings. For the regular SDK (e.g., non-Web), this generated C# looks like:
However, System.Net.Http is a namespace that does not exist in .NET Framework 4.x. Therefore, this namespace should not be imported implicitly.
To Reproduce
A
csproj
like this will suffice:This will fail to build with:
The text was updated successfully, but these errors were encountered: