Skip to content

Align Microsoft.NET.Sdk implicit usings with ASP.NET Core by adding System.Net.Http.Json for net11+#54272

Merged
marcpopMSFT merged 10 commits into
mainfrom
copilot/add-using-system-net-http-json
May 13, 2026
Merged

Align Microsoft.NET.Sdk implicit usings with ASP.NET Core by adding System.Net.Http.Json for net11+#54272
marcpopMSFT merged 10 commits into
mainfrom
copilot/add-using-system-net-http-json

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

Console apps using Microsoft.NET.Sdk require an explicit using System.Net.Http.Json; where ASP.NET Core apps do not. This change aligns implicit-using behavior by including System.Net.Http.Json in default C# implicit usings for .NETCoreApp targeting 11.0+.

  • SDK implicit usings update

    • Updated src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CSharp.props to include:
      • System.Net.Http.Json when:
        • $(TargetFrameworkIdentifier) == '.NETCoreApp'
        • $(TargetFrameworkVersion) >= 11.0
  • Global usings test expectations

    • Updated test/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_DotNet.cs expected generated .GlobalUsings.g.cs content for current target framework behavior.
    • Updated test/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_Worker.cs (It_generates_worker_implicit_usings_and_builds_successfully) to include global using System.Net.Http.Json;.
    • Added coverage in GivenThatWeWantToGenerateGlobalUsings_DotNet.cs to verify System.Net.Http.Json is not generated for net10.0, validating the net11 gate.
<ItemGroup Condition="'$(ImplicitUsings)' == 'true' Or '$(ImplicitUsings)' == 'enable'">
  <Using Include="System.Net.Http" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'"/>
  <Using Include="System.Net.Http.Json"
         Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '11.0'))" />
</ItemGroup>

Copilot AI and others added 2 commits May 12, 2026 21:06
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/eaaeabc9-bedc-4fbc-a2c9-da55d5c04660

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Copilot AI changed the title [WIP] Add implicit using for System.Net.Http.Json in net8.0 Align Microsoft.NET.Sdk implicit usings with ASP.NET Core by adding System.Net.Http.Json for net8+ May 12, 2026
Copilot AI requested a review from marcpopMSFT May 12, 2026 21:14
@marcpopMSFT
Copy link
Copy Markdown
Member

@copilot make the condition be net11 or higher as this is a breaking change for anyone who's made IDE0005 a higher severity than a message. Also, you need to fix the It_generates_worker_implicit_usings_and_builds_successfully test as it now includes the new using

Copilot AI and others added 5 commits May 12, 2026 23:48
…ker test

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/a9c4bb5a-f14d-43b3-9cf2-9a0812277758

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/a9c4bb5a-f14d-43b3-9cf2-9a0812277758

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/a9c4bb5a-f14d-43b3-9cf2-9a0812277758

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/a9c4bb5a-f14d-43b3-9cf2-9a0812277758

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot make the condition be net11 or higher as this is a breaking change for anyone who's made IDE0005 a higher severity than a message. Also, you need to fix the `It_generates_worker_implicit_usin...

Updated as requested: System.Net.Http.Json implicit-using is now gated to net11+ and It_generates_worker_implicit_usings_and_builds_successfully now expects it. I also added a net10.0 regression test to verify the gate. Addressed in df98a54 (plus supporting commits bd88889 and 684ef5b).

Copilot AI changed the title Align Microsoft.NET.Sdk implicit usings with ASP.NET Core by adding System.Net.Http.Json for net8+ Align Microsoft.NET.Sdk implicit usings with ASP.NET Core by adding System.Net.Http.Json for net11+ May 12, 2026
@baronfel
Copy link
Copy Markdown
Member

@copilot this change broke the run-file tests. Analyze and attempt to fix those as well.

cc @jjonescz

Copilot AI and others added 2 commits May 13, 2026 14:12
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 13, 2026

@copilot this change broke the run-file tests. Analyze and attempt to fix those as well.

cc @jjonescz

Fixed and validated. The run-file regression was in csc-only global usings generation (CSharpCompilerCommand.Generated.cs) missing System.Net.Http.Json, which made RunFileTests_CscOnlyAndApi.CscVsMSBuild fail after the net11+ implicit-using change. Updated it to match MSBuild output and verified targeted run-file + implicit-usings tests pass. Addressed in 76e44fb.

Copilot AI requested a review from baronfel May 13, 2026 14:28
@baronfel baronfel marked this pull request as ready for review May 13, 2026 14:40
Copilot AI review requested due to automatic review settings May 13, 2026 14:40
@baronfel
Copy link
Copy Markdown
Member

@marcpopMSFT it looks like Copilot did a good job with the http Using - should we have it go ahead and do the Extensions ones we spoke about during triage as well?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns Microsoft.NET.Sdk (console/standard SDK) C# implicit-usings behavior with ASP.NET Core for .NET 11+ by implicitly adding System.Net.Http.Json for .NETCoreApp projects targeting 11.0+, and updates tests/templates that assert generated global-usings content.

Changes:

  • Add System.Net.Http.Json to default C# implicit usings for .NETCoreApp when TargetFrameworkVersion >= 11.0.
  • Update Microsoft.NET.Sdk and Microsoft.NET.Sdk.Worker global-usings generation tests to include the new implicit using for the current TFM (net11).
  • Add a regression test ensuring System.Net.Http.Json is not generated when targeting net10.0, and update the dotnet run file.cs CSC-only template to match MSBuild output for net11.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
test/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_Worker.cs Updates worker implicit-usings expectation to include System.Net.Http.Json for current TFM.
test/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_DotNet.cs Updates baseline expectations for net11 and adds a net10 gate test to validate the new condition.
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CSharp.props Adds the new conditional implicit using for .NETCoreApp targeting net11+.
src/Cli/dotnet/Commands/Run/CSharpCompilerCommand.Generated.cs Updates CSC-only auxiliary GlobalUsings template to stay aligned with MSBuild for net11+.

@baronfel
Copy link
Copy Markdown
Member

/ba-g NetAnalyzer crash that's unreleated

@marcpopMSFT
Copy link
Copy Markdown
Member

@marcpopMSFT it looks like Copilot did a good job with the http Using - should we have it go ahead and do the Extensions ones we spoke about during triage as well?

@baronfel talked to @ericstj offline and he says no as they are only pushing the abstractions, not the full E2E.

@marcpopMSFT marcpopMSFT merged commit db32d84 into main May 13, 2026
25 of 29 checks passed
@marcpopMSFT marcpopMSFT deleted the copilot/add-using-system-net-http-json branch May 13, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implicit using for console apps and ASP.NET Core don't match

4 participants