Skip to content

Make Microsoft.NET.Build.Tasks AOT/trim compatible#55062

Merged
baronfel merged 1 commit into
dotnet:mainfrom
JeremyKuhne:build-tasks-aot-compat
Jun 30, 2026
Merged

Make Microsoft.NET.Build.Tasks AOT/trim compatible#55062
baronfel merged 1 commit into
dotnet:mainfrom
JeremyKuhne:build-tasks-aot-compat

Conversation

@JeremyKuhne

Copy link
Copy Markdown
Member

Summary

Enables IsAotCompatible for the Microsoft.NET.Build.Tasks project and resolves the resulting IL trim/AOT analyzer warnings.

The only warnings (IL2026/IL3050) came from the reflection-based Newtonsoft.Json serializer used by GenerateRuntimeConfigurationFiles to 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

  • Add <IsAotCompatible> (conditioned on net8.0+, so net472 is unaffected and no NETSDK1210 is emitted).
  • Migrate GenerateRuntimeConfigurationFiles serialization from Newtonsoft.Json LINQ-to-JSON to System.Text.Json nodes. The writer uses Indented = true, NewLine = Environment.NewLine, and Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping so indentation, line endings, and escaping match the previous output.
  • Change RuntimeOptions.RawOptions (the extension-data bag) from IDictionary<string, JToken> to IDictionary<string, JsonNode>, and drop the now-unneeded [JsonProperty] / [JsonExtensionData] attributes.
  • Add exact-output regression tests for config properties, additional probing paths, and user runtime config template merging.

Validation

  • 0 IL warnings; both net11.0 and net472 build clean.
  • All GenerateRuntimeConfig task tests pass (existing + new exact-output tests).
  • An old-vs-new characterization confirmed byte-identical output across every branch and escaping case (backslashes, +, <>&, non-ASCII Unicode, quotes, control characters, null extension data, nested structures).

Notes

  • One intentional nuance: numbers written in scientific notation inside a user runtimeconfig.template.json round-trip slightly differently (Newtonsoft normalized 1e10 to 10000000000.0; System.Text.Json preserves the literal 1e10). 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.Json remains a transitive dependency (via NuGet.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.

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.
Copilot AI review requested due to automatic review settings June 29, 2026 22:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@baronfel baronfel merged commit d14c9a3 into dotnet:main Jun 30, 2026
26 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 1, 2026
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.

3 participants