Make Microsoft.NET.Build.Tasks AOT/trim compatible#55062
Merged
Conversation
Enable IsAotCompatible for the Microsoft.NET.Build.Tasks project (scoped to net8.0+ so net472 is unaffected) and resolve the resulting IL trim/AOT analyzer warnings. The only warnings (IL2026/IL3050) came from the reflection-based Newtonsoft.Json serializer used to write .runtimeconfig.json files. Replace that usage with the System.Text.Json node API, configured to reproduce the previous output exactly: 2-space indentation, environment newlines, relaxed escaping, and the same property ordering. RuntimeOptions' extension-data bag changes from IDictionary<string, JToken> to IDictionary<string, JsonNode> accordingly. Add exact-output regression tests covering config properties, additional probing paths, and user runtime config template merging.
baronfel
approved these changes
Jun 30, 2026
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.
Summary
Enables
IsAotCompatiblefor theMicrosoft.NET.Build.Tasksproject and resolves the resulting IL trim/AOT analyzer warnings.The only warnings (IL2026/IL3050) came from the reflection-based Newtonsoft.Json serializer used by
GenerateRuntimeConfigurationFilesto write.runtimeconfig.json/.runtimeconfig.dev.json. This replaces that usage with the System.Text.Json node API (JsonObject/JsonArray/JsonNode+Utf8JsonWriter), configured to reproduce the previous output exactly.Changes
<IsAotCompatible>(conditioned on net8.0+, so net472 is unaffected and noNETSDK1210is emitted).GenerateRuntimeConfigurationFilesserialization from Newtonsoft.Json LINQ-to-JSON to System.Text.Json nodes. The writer usesIndented = true,NewLine = Environment.NewLine, andEncoder = JavaScriptEncoder.UnsafeRelaxedJsonEscapingso indentation, line endings, and escaping match the previous output.RuntimeOptions.RawOptions(the extension-data bag) fromIDictionary<string, JToken>toIDictionary<string, JsonNode>, and drop the now-unneeded[JsonProperty]/[JsonExtensionData]attributes.Validation
net11.0andnet472build clean.GenerateRuntimeConfigtask tests pass (existing + new exact-output tests).+,<>&, non-ASCII Unicode, quotes, control characters, null extension data, nested structures).Notes
runtimeconfig.template.jsonround-trip slightly differently (Newtonsoft normalized1e10to10000000000.0; System.Text.Json preserves the literal1e10). Plain integers, decimals, negatives, and zero are unchanged. This is semantically identical to the host, effectively never occurs in practice, and STJ's behavior is more faithful to the user's input.Newtonsoft.Jsonremains a transitive dependency (viaNuGet.Packaging) and is still used by a few other files in this project. This change only removes its use from runtime config generation to clear the AOT analyzer warnings.