Migrate direct Newtonsoft.Json usage to System.Text.Json#54064
Merged
JeremyKuhne merged 1 commit intodotnet:mainfrom Apr 28, 2026
Merged
Migrate direct Newtonsoft.Json usage to System.Text.Json#54064JeremyKuhne merged 1 commit intodotnet:mainfrom
JeremyKuhne merged 1 commit intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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-tasksand CLI components withSystem.Text.Json(JsonNode,JsonSerializer) and removed direct Newtonsoft.Json package references. - Added source-generated
JsonSerializerContexttypes for installer IPC/manifest serialization and forsdk-tasksanalyzer 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). |
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>
NikolaMilosavljevic
approved these changes
Apr 28, 2026
MiYanni
approved these changes
Apr 28, 2026
Member
Author
|
/ba-g Only failure was outside of this PR and fixed in 751ee3b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.