Skip to content

Migrate direct Newtonsoft.Json usage to System.Text.Json#54064

Merged
JeremyKuhne merged 1 commit intodotnet:mainfrom
JeremyKuhne:stjit
Apr 28, 2026
Merged

Migrate direct Newtonsoft.Json usage to System.Text.Json#54064
JeremyKuhne merged 1 commit intodotnet:mainfrom
JeremyKuhne:stjit

Conversation

@JeremyKuhne
Copy link
Copy Markdown
Member

Replace production CLI and sdk-tasks Newtonsoft.Json usage with System.Text.Json APIs, including JsonNode-based DOM handling and source-generated serializer contexts for AOT/trimming-safe serialization.

Enable AOT compatibility for sdk-tasks, remove direct Newtonsoft.Json package references from migrated projects, and add coverage for JSON mutation helpers, installer serialization, host data, aliases, and TemplateEngine CLI parsing parity.

Copilot AI review requested due to automatic review settings April 24, 2026 21:04
@JeremyKuhne JeremyKuhne requested a review from a team as a code owner April 24, 2026 21:04
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

Migrates remaining direct Newtonsoft.Json usage in dotnet CLI and sdk-tasks to System.Text.Json, including moving to JsonNode DOM manipulation and adding source-generated serializer contexts to improve AOT/trimming compatibility.

Changes:

  • Replaced JSON parsing/mutation code in sdk-tasks and CLI components with System.Text.Json (JsonNode, JsonSerializer) and removed direct Newtonsoft.Json package references.
  • Added source-generated JsonSerializerContext types for installer IPC/manifest serialization and for sdk-tasks analyzer metadata output.
  • Added/updated unit tests to validate JSON mutation helpers, TemplateEngine JSON helpers, host data handling, and alias parsing behavior.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test/sdk-tasks.Tests/UpdateRuntimeConfigTests.cs Adds coverage for runtimeconfig framework version updates.
test/sdk-tasks.Tests/RemoveAssetFromDepsPackagesTests.cs Adds coverage for .deps.json asset/section removal behavior.
test/sdk-tasks.Tests/PublishMutationUtilitiesTests.cs Adds coverage for entry-point library rename/removal in .deps.json.
test/Microsoft.TemplateEngine.Cli.UnitTests/Microsoft.TemplateEngine.Cli.UnitTests.csproj Adds an extern alias for the CLI project reference to test internal APIs cleanly.
test/Microsoft.TemplateEngine.Cli.UnitTests/JExtensionsTests.cs Adds a focused test for JExtensions.ToInt32 behavior with string values.
test/Microsoft.TemplateEngine.Cli.UnitTests/HostDataLoaderTests.cs Switches tests from JObject to JsonNode checks for host data serialization.
test/Microsoft.TemplateEngine.Cli.UnitTests/AliasAssignmentTests.cs Switches alias-related tests from JObject/JArray to JsonNode/JsonArray.
src/Tasks/sdk-tasks/sdk-tasks.csproj Enables AOT compatibility and removes direct Newtonsoft.Json package reference.
src/Tasks/sdk-tasks/UpdateRuntimeConfig.cs Replaces JObject/JToken runtimeconfig mutation with JsonNode.
src/Tasks/sdk-tasks/RemoveAssetFromDepsPackages.cs Replaces Newtonsoft-based .deps.json edits with JsonNode and ToJsonString.
src/Tasks/sdk-tasks/PublishMutationUtilities.cs Replaces Newtonsoft-based .deps.json edits with JsonNode and ToJsonString.
src/Tasks/sdk-tasks/ProcessRuntimeAnalyzerVersions.cs Uses source-generated serialization for metadata output and adds a context type.
src/Tasks/sdk-tasks/GetRuntimePackRids.cs Switches runtime.json RID extraction from JObject to JsonNode.
src/Cli/dotnet/dotnet.csproj Removes direct Newtonsoft.Json package reference from the CLI.
src/Cli/dotnet/ToolPackage/ToolPackageDownloaderBase.cs Switches runtimeconfig update logic from JObject to JsonNode.
src/Cli/dotnet/Installer/Windows/RelatedProduct.cs Removes Newtonsoft-specific converters/attributes in preparation for STJ serialization.
src/Cli/dotnet/Installer/Windows/MsiPayload.cs Switches manifest deserialization to STJ with source-generated context.
src/Cli/dotnet/Installer/Windows/MsiPackageCache.cs Switches manifest deserialization to STJ with source-generated context.
src/Cli/dotnet/Installer/Windows/InstallerJsonSerializerContext.cs Adds source-generated context for installer request/response/manifest types.
src/Cli/dotnet/Installer/Windows/InstallResponseMessage.cs Switches IPC message deserialization to STJ with source-generated context.
src/Cli/dotnet/Installer/Windows/InstallRequestMessage.cs Switches IPC message deserialization to STJ with source-generated context.
src/Cli/dotnet/Installer/Windows/InstallMessageBase.cs Switches message serialization to STJ using the generated context.
src/Cli/dotnet/Commands/New/MSBuildEvaluation/ProjectCapabilityConstraint.cs Replaces JToken parsing with JsonNode/JsonValueKind checks for constraint args.
src/Cli/Microsoft.TemplateEngine.Cli/TemplateSearch/CliHostSearchCacheData.cs Replaces JObject-based cache reading with JsonObject iteration.
src/Cli/Microsoft.TemplateEngine.Cli/PostActionProcessors/PostActionProcessorBase.cs Replaces JToken/JArray parsing with JsonNode/JsonArray handling.
src/Cli/Microsoft.TemplateEngine.Cli/PostActionProcessors/ChmodPostActionProcessor.cs Replaces JArray parsing with JsonNode/JsonArray parsing.
src/Cli/Microsoft.TemplateEngine.Cli/JExtensions.cs Reimplements JSON helper extensions on JsonNode + adds typed writer helper for source-gen.
src/Cli/Microsoft.TemplateEngine.Cli/HostSpecificTemplateData.cs Replaces JObject/JArray host data parsing and updates custom converter to STJ APIs.
src/Cli/Microsoft.TemplateEngine.Cli/HostSpecificDataLoader.cs Replaces stream-based Newtonsoft parsing with STJ parsing (via ParseJsonObject).
src/Cli/Microsoft.TemplateEngine.Cli/Alias/AliasRegistry.cs Updates alias file I/O to use STJ helpers and a source-generated context.
src/Cli/Microsoft.TemplateEngine.Cli/Alias/AliasModel.cs Switches serialization attributes from Newtonsoft to STJ (JsonInclude).

Comment thread test/sdk-tasks.Tests/RemoveAssetFromDepsPackagesTests.cs Outdated
Comment thread test/sdk-tasks.Tests/PublishMutationUtilitiesTests.cs Outdated
Comment thread src/Cli/Microsoft.TemplateEngine.Cli/TemplateSearch/CliHostSearchCacheData.cs Outdated
Comment thread src/Cli/Microsoft.TemplateEngine.Cli/JExtensions.cs
Comment thread src/Cli/dotnet/Installer/Windows/InstallResponseMessage.cs Outdated
Comment thread src/Cli/dotnet/Installer/Windows/InstallRequestMessage.cs Outdated
Comment thread test/sdk-tasks.Tests/UpdateRuntimeConfigTests.cs Outdated
Replace production CLI and sdk-tasks Newtonsoft.Json usage with System.Text.Json APIs,
including JsonNode-based DOM handling and source-generated serializer contexts for
AOT/trimming-safe serialization.

Enable AOT compatibility for sdk-tasks, remove direct Newtonsoft.Json package
references from migrated projects, and add coverage for JSON mutation helpers,
installer serialization, host data, aliases, and TemplateEngine CLI parsing parity.

Co-authored-by: Copilot <copilot@github.com>
@JeremyKuhne
Copy link
Copy Markdown
Member Author

/ba-g Only failure was outside of this PR and fixed in 751ee3b

@JeremyKuhne JeremyKuhne merged commit 1d4ed8a into dotnet:main Apr 28, 2026
21 of 24 checks passed
@JeremyKuhne JeremyKuhne deleted the stjit branch April 28, 2026 21:22
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.

4 participants