Align Microsoft.NET.Sdk implicit usings with ASP.NET Core by adding System.Net.Http.Json for net11+#54272
Conversation
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/eaaeabc9-bedc-4fbc-a2c9-da55d5c04660 Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/eaaeabc9-bedc-4fbc-a2c9-da55d5c04660 Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Microsoft.NET.Sdk implicit usings with ASP.NET Core by adding System.Net.Http.Json for net8+
|
@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 |
…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>
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/a9c4bb5a-f14d-43b3-9cf2-9a0812277758 Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Updated as requested: |
Microsoft.NET.Sdk implicit usings with ASP.NET Core by adding System.Net.Http.Json for net8+Microsoft.NET.Sdk implicit usings with ASP.NET Core by adding System.Net.Http.Json for net11+
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/b7986fd2-e64d-448d-97ae-f84c4e1deb0e Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/b7986fd2-e64d-448d-97ae-f84c4e1deb0e Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Fixed and validated. The run-file regression was in csc-only global usings generation ( |
|
@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? |
There was a problem hiding this comment.
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.Jsonto default C# implicit usings for.NETCoreAppwhenTargetFrameworkVersion >= 11.0. - Update
Microsoft.NET.SdkandMicrosoft.NET.Sdk.Workerglobal-usings generation tests to include the new implicit using for the current TFM (net11). - Add a regression test ensuring
System.Net.Http.Jsonis not generated when targetingnet10.0, and update thedotnet run file.csCSC-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+. |
|
/ba-g NetAnalyzer crash that's unreleated |
@baronfel talked to @ericstj offline and he says no as they are only pushing the abstractions, not the full E2E. |
Console apps using
Microsoft.NET.Sdkrequire an explicitusing System.Net.Http.Json;where ASP.NET Core apps do not. This change aligns implicit-using behavior by includingSystem.Net.Http.Jsonin default C# implicit usings for.NETCoreApptargeting11.0+.SDK implicit usings update
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CSharp.propsto include:System.Net.Http.Jsonwhen:$(TargetFrameworkIdentifier) == '.NETCoreApp'$(TargetFrameworkVersion) >= 11.0Global usings test expectations
test/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_DotNet.csexpected generated.GlobalUsings.g.cscontent for current target framework behavior.test/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateGlobalUsings_Worker.cs(It_generates_worker_implicit_usings_and_builds_successfully) to includeglobal using System.Net.Http.Json;.GivenThatWeWantToGenerateGlobalUsings_DotNet.csto verifySystem.Net.Http.Jsonis not generated fornet10.0, validating the net11 gate.