Repository navigation
[Microsoft.Android.Build.Tasks] Move MamJsonToXml to .NET - #13459
Conversation
…sembly
Move the `<MamJsonToXml/>` task and its `MamJsonParser` helper from
`Xamarin.Android.Build.Tasks` into `Microsoft.Android.Build.Tasks`, so
it runs on .NET with the framework-provided System.Text.Json.
* `Xamarin.Android.Common.targets` registers
`Microsoft.Android.Tasks.MamJsonToXml` with the existing Full/Core
`UsingTask` pair (TaskHostFactory + Runtime="NET" on .NET Framework
MSBuild, in-proc Runtime="NET" on .NET MSBuild). The `<MamJsonToXml/>`
element name and parameters used by
`_ConvertAndroidMamMappingFileToXmlFile` are unchanged.
* The task derives from `MultithreadedAndroidTask`, is marked
`[MSBuildMultiThreadableTask]`, and resolves input/output paths via
`TaskEnvironment`. `MamJsonParser.Load()` now takes a `Stream` so the
task owns file access; parsing and XML generation are unchanged.
* `JsonExtensions.cs` is linked (not moved), since the legacy
`BuildAppBundle` task still uses it, and the legacy
System.Text.Json PackageReference is left in place.
* The task test and its mam.json/mam.xml fixtures move to
`Microsoft.Android.Build.Tasks.Tests`.
The public `Xamarin.Android.Tasks.MamJsonToXml` type is removed from
`Xamarin.Android.Build.Tasks.dll`; only the MSBuild task contract is
preserved.
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The required XmlMappingOutput parameter is nullable and defaults to null; it should expose a non-nullable contract while retaining explicit validation for unset or empty output items.
1 open issue
What changed in this PR
Moves MAM JSON-to-XML conversion into Microsoft.Android.Build.Tasks to use framework-provided System.Text.Json, continuing the build-tool modernization described in #12988 without depending on it.
Changes:
- Migrates the task and parser, adding multithreaded task support and project-relative path resolution.
- Updates Full/Core MSBuild registrations while preserving the short task name and parameters.
- Relocates the conversion test and fixtures to the modern task test project.
| File | Description |
|---|---|
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets |
Registers the modern task for Full/Core MSBuild. |
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ResourceData.cs |
Removes obsolete MAM fixture accessors. |
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/MamJsonToXmlTests.cs |
Removes the legacy test implementation. |
src/Xamarin.Android.Build.Tasks/MamJsonToXml.cs |
Removes the legacy public task type. |
src/Microsoft.Android.Build.Tasks/Utilities/MamJsonParser.cs |
Moves the parser namespace and accepts an open stream. |
src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Resources/MamJsonToXml/mam.xml |
Supplies the expected XML fixture. |
src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Resources/MamJsonToXml/mam.json |
Supplies the JSON input fixture. |
src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj |
Copies MAM fixtures to test output. |
src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/MamJsonToXmlTests.cs |
Tests conversion with project-relative paths and normalized line endings. |
src/Microsoft.Android.Build.Tasks/Tasks/MamJsonToXml.cs |
Adds the modern task using TaskEnvironment. |
src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj |
Links the existing JSON extension helpers. |
Review effort: Balanced
Context: #13459 Keep task registration attribute-free so Core MSBuild loads the modern MamJsonToXml implementation in process, while every non-Core host continues to load the legacy class and assembly. The mutually exclusive Core/non-Core conditions retain coverage for Full, Mono, and any other non-Core host without depending on Runtime or TaskFactory hosting support. Restore the legacy task, tests, and fixtures. Compile-link MamJsonParser and JsonExtensions into the modern assembly instead of maintaining separate parser implementations; the legacy path-based parser entry point delegates to the shared stream-based implementation. Keep the legacy System.Text.Json package dependency. The modern task continues to reuse MultithreadedAndroidTask and the framework-provided JSON library. Focused tests pass for both the net11 legacy task (1 test) and net12 modern task (2 tests). Ordinary and strict multithreaded Core MSBuild runs execute the production MAM targets and produce byte-identical XML. Full/Mono host execution remains unvalidated on macOS. Co-authored-by: Copilot App <[email protected]>
Context: #13459 Make Microsoft.Android.Build.Tasks the canonical source owner for MamJsonParser and JsonExtensions. Link those sources back into Xamarin.Android.Build.Tasks so its non-Core compatibility implementation and other legacy JSON consumers continue to work without duplicated helper code. This keeps ownership aligned with the eventual removal of the legacy task project. Both helper moves are byte-preserving. Focused modern tests pass 2/2; legacy MAM, JsonExtensions, and bundle-tool tests pass 7/7. Ordinary and strict multithreaded Core MSBuild smoke runs still load the modern task and produce XML byte-identical to the original fixture and baseline. Full/Mono host execution remains unvalidated on macOS. Co-authored-by: Copilot App <[email protected]>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
✅ LGTM — source review
Findings: 0 errors, 0 warnings, 1 non-blocking inline suggestion.
Reviewed all eight changed files in full, the parser's callers, the task base/logger, project references, and the consuming remapping targets. The mutually exclusive registrations preserve the legacy non-Core implementation, while Core uses the modern assembly. The modern adapter resolves both input and output paths through TaskEnvironment; parser state remains per task, and the stream overload preserves the existing parsing options and XML conversion. Reusing the canonical parser sources avoids conversion drift between hosts. No blocking correctness regression found.
CI evidence: All 40 GitHub checks report success, including the overall dotnet-android check for Azure build 1673210. Direct Azure build/timeline verification could not be completed: the CLI required authentication and the parallel timeline query failed during CLI initialization. This is not an independent Azure timeline confirmation.
Local validation: Attempted dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -c Release -v minimal --filter FullyQualifiedName~MamJsonToXmlTests --no-restore; the .NET CLI failed before building or running tests while initializing the NuGet-Migrations mutex. No local test result is claimed. Full/Mono host execution also remains unverified here, consistent with the limitation documented in the PR.
Generated by Android PR Reviewer for #13459 · copilot · gpt61 · 40 AIC · ⌖ 4.96 AIC · ⊞ 20.1K
Comment /review to run again
Co-authored-by: Copilot App <[email protected]>
The BuildAppBundle migration on main reintroduced a link to the legacy path after the MAM migration moved JsonExtensions into the modern task project. Use the SDK's default source inclusion instead. Co-authored-by: Copilot App <[email protected]>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
No blocking code findings — 0 errors, 0 warnings, 1 non-blocking inline suggestion.
Reviewed all nine changed files in full, the calling target, task base classes, and logging paths. The Core/non-Core registrations are mutually exclusive, the modern task declares multithreaded support and resolves both input and output paths through TaskEnvironment, and the shared parser preserves the existing conversion and stream-disposal behavior. Keeping the legacy sources compile-linked and its System.Text.Json dependency intact preserves the current netstandard2.0 fallback. The documented integration overlap with #12988 remains relevant if the changes are combined.
CI verification incomplete: all 40 head-commit GitHub checks report success, including the aggregate dotnet-android check for Azure build 1678722. Direct Azure build/timeline confirmation was unavailable: the build query required authentication and the concurrent timeline query failed during CLI initialization. No CI failure was observed, but I cannot independently confirm the Azure result. This was a source review; local builds/tests were not rerun.
Generated by Android PR Reviewer for #13459 · copilot · gpt61 · 35.9 AIC · ⌖ 4.14 AIC · ⊞ 20.2K
Comment /review to run again
| BuildEngine = new MockBuildEngine (TestContext.Out, errors), | ||
| }; | ||
| if (supplyEmptyItem) { | ||
| task.XmlMappingOutput = new TaskItem (""); |
There was a problem hiding this comment.
🤖 💡 Testing — Both cases currently exercise an empty TaskItem: when supplyEmptyItem is false, XmlMappingOutput retains its new TaskItem ("") default; when true, it is replaced with an equivalent item. Consider adding an explicit XmlMappingOutput = null case (keeping the omitted/default and explicit-empty cases if desired) so the separate null guard in RunTask() is covered as well.
{Rule: Test edge cases}
Co-authored-by: Copilot App <[email protected]>
Keep the Lint shared helper and Java dependency test entries while moving JsonExtensions and adding the MAM test resources. Co-authored-by: Copilot App <[email protected]>
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed e5c17ef7 against main at b0843532 (merge-base b0843532). This was a static, read-only review. I didn't build or run anything.
LGTM. I compared the move against the full old files.
- Parser and helper:
MamJsonParseronly gains aLoad(Stream)overload. Parse options (AllowTrailingCommas), the empty-object fallback and the XML generation are unchanged.JsonExtensions.csis byte-identical. - Task:
MamJsonToXmlkeeps the same[Required]inputs and output. Paths go throughTaskEnvironment.GetAbsolutePath, and each stream is disposed. - Registration: the Full (
TaskHostFactory,Runtime="NET") and CoreUsingTaskentries match the other moved tasks and point at the shippedtools\netassembly. The call site keeps the short name and the same parameters. - Project files: the SDK-style csproj globs the moved utilities, and XABT links
JsonExtensions.csback so its other users andJsonExtensionsTestsstill compile.create-installers.targetsalready ships thenetassembly, so no packaging change is needed. - Tests: the new tests line up with the shared infrastructure.
MultithreadedAndroidTaskcatches the guard's exception and logs it with aFallbackTaskEnvironment,MockBuildEnginehas the overload the tests call, and the linkedmam.json/mam.xmlresources exist.

Context: #12988
<MamJsonToXml/>currently runs from thenetstandard2.0task assembly and uses its System.Text.Json package. Move the task and parser toMicrosoft.Android.Build.Tasksso the task uses the framework-provided JSON implementation. Delete the legacy task rather than maintain two implementations. The legacy assembly still retains its System.Text.Json package and compile-linksJsonExtensions.csfor other consumers.Register the .NET task for both Core and Full MSBuild. Full uses
Runtime="NET"andTaskHostFactory, following the other .NET task registrations. The task retains the existing MSBuild parameters and XML conversion, supports multithreaded execution, and resolves paths throughTaskEnvironment.Validation (current head):
Full/Mono-hosted execution was not tested on macOS. Earlier revisions passed
make leeroy CONFIGURATION=Release, the complete modern suite (871 passed, 5 skipped), andMamRemappingTransitionsUpdatePackages(3/3); those runs were not repeated after the final registration changes.