Repository navigation
[Build.Tasks] Resolve centrally managed NuGet package versions - #13533
Conversation
Move the `<JavaDependencyVerification/>` task, and the `NuGetPackageVersionFinder`, `MicrosoftNuGetPackageFinder`, and POM-resolution helpers that only it uses, from `Xamarin.Android.Build.Tasks.dll` (netstandard2.0) into `Microsoft.Android.Build.Tasks.dll` (net12.0). The task keeps its `Xamarin.Android.Tasks` namespace, so both the qualified `Xamarin.Android.Tasks.JavaDependencyVerification` and the short `<JavaDependencyVerification/>` names continue to resolve. It is registered with the same `UsingTask` pair used by the other tasks in `Microsoft.Android.Build.Tasks.dll`: `Runtime="NET"` under .NET MSBuild, plus `TaskFactory="TaskHostFactory"` under .NET Framework MSBuild. The task still derives from `AndroidTask`, so path handling is unchanged; converting it to `MultithreadedAndroidTask` would resolve Windows drive-relative paths such as `D:foo` differently, so that is left for a separate change. Under `-mt` it runs in a task host, as it did before. Split the artifact-parsing and dependency-scope helpers out of `MavenExtensions` into a `Microsoft.Android.Build.Tasks` copy; the download helpers stay in `Xamarin.Android.Build.Tasks.dll` for `<MavenDownload/>`. `NuGet.Versioning` is now referenced only by `Microsoft.Android.Build.Tasks`, and it and `Java.Interop.Tools.Maven` ship in `tools/net/`. `Java.Interop.Tools.Maven.dll` also remains in `tools/` for `<MavenDownload/>`. The task's unit tests move to `Microsoft.Android.Build.Tasks.Tests`. Co-authored-by: Copilot App <[email protected]>
…oid.Tasks` Context: 8aa7820 Like `<BuildAppBundle/>` in #13460, tasks moved into `Microsoft.Android.Build.Tasks.dll` use the `Microsoft.Android.Tasks` namespace, and only the new qualified task name is registered. `<JavaDependencyVerification/>` continues to resolve by its short name. Co-authored-by: Copilot App <[email protected]>
Remove the duplicate metadata-default helper; the moved task uses TaskItemExtensions. Check in a two-project fixture that imports the shipped registration, invokes the short task name, and satisfies a POM dependency through NuGet assets and nuspec tags under ordinary and strict multithreaded MSBuild. Co-authored-by: Copilot App <[email protected]>
Central Package Management leaves PackageReference.Version empty. Java dependency verification passed that value to NuGetVersion and failed with ArgumentException instead of reporting missing Java dependencies. Use the restored version from project.assets.json when exactly one version exists. Keep explicit version lookup and JavaArtifact overrides, and report XA4248 for missing or ambiguous package versions without guessing. Add regression tests for CPM, VersionOverride, NuGet version semantics, explicit JavaArtifact metadata, and XA4241/XA4242 diagnostics. Fixes: #10353 Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the changes to centrally managed NuGet version resolution.
No open issues 🎉
What changed in this PR
Fixes #10353 in the migrated Java dependency verification task by resolving centrally managed NuGet package versions from project.assets.json, avoiding exceptions when PackageReference.Version is empty.
Changes:
- Uses the restored version when exactly one exists, while preserving explicit version lookup and
JavaArtifactoverrides. - Reports XA4248 for missing, invalid, or ambiguous versions instead of throwing or choosing arbitrarily.
- Adds regression coverage and documents how to resolve ambiguous versions.
| File | Description |
|---|---|
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/NuGetPackageVersionFinderTests.cs | Adds coverage for central versions, overrides, unresolved packages, and dependency diagnostics. |
| src/Microsoft.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs | Resolves empty versions from restored packages and safely handles failed lookups. |
| Documentation/docs-mobile/messages/xa4248.md | Explains central package resolution and the JavaArtifact workaround for ambiguity. |
Review effort: Balanced
Keep five focused cases for CPM success, ambiguous restored versions, JavaArtifact precedence, and missing Java dependency diagnostics. Remove duplicate lookup and VersionOverride cases, and keep the shared assets fixture unchanged. Co-authored-by: Copilot App <[email protected]>
Move the `<JavaDependencyVerification/>` task, and the `NuGetPackageVersionFinder`, `MicrosoftNuGetPackageFinder`, and POM-resolution helpers that only it uses, from `Xamarin.Android.Build.Tasks.dll` (netstandard2.0) into `Microsoft.Android.Build.Tasks.dll` (net12.0). The task keeps its `Xamarin.Android.Tasks` namespace, so both the qualified `Xamarin.Android.Tasks.JavaDependencyVerification` and the short `<JavaDependencyVerification/>` names continue to resolve. It is registered with the same `UsingTask` pair used by the other tasks in `Microsoft.Android.Build.Tasks.dll`: `Runtime="NET"` under .NET MSBuild, plus `TaskFactory="TaskHostFactory"` under .NET Framework MSBuild. The task still derives from `AndroidTask`, so path handling is unchanged; converting it to `MultithreadedAndroidTask` would resolve Windows drive-relative paths such as `D:foo` differently, so that is left for a separate change. Under `-mt` it runs in a task host, as it did before. Split the artifact-parsing and dependency-scope helpers out of `MavenExtensions` into a `Microsoft.Android.Build.Tasks` copy; the download helpers stay in `Xamarin.Android.Build.Tasks.dll` for `<MavenDownload/>`. `NuGet.Versioning` is now referenced only by `Microsoft.Android.Build.Tasks`, and it and `Java.Interop.Tools.Maven` ship in `tools/net/`. `Java.Interop.Tools.Maven.dll` also remains in `tools/` for `<MavenDownload/>`. The task's unit tests move to `Microsoft.Android.Build.Tasks.Tests`. Co-authored-by: Copilot App <[email protected]>
…oid.Tasks` Context: 8aa7820 Like `<BuildAppBundle/>` in #13460, tasks moved into `Microsoft.Android.Build.Tasks.dll` use the `Microsoft.Android.Tasks` namespace, and only the new qualified task name is registered. `<JavaDependencyVerification/>` continues to resolve by its short name. Co-authored-by: Copilot App <[email protected]>
Remove the duplicate metadata-default helper; the moved task uses TaskItemExtensions. Check in a two-project fixture that imports the shipped registration, invokes the short task name, and satisfies a POM dependency through NuGet assets and nuspec tags under ordinary and strict multithreaded MSBuild. Co-authored-by: Copilot App <[email protected]>
Exercise the .NET task host using a compatible Windows MSBuild installation and require the test on Windows CI. Co-authored-by: Copilot App <[email protected]>
Preserve the parent's Full MSBuild hosting coverage and installer inputs alongside the five focused CPM regression cases. Co-authored-by: Copilot App <[email protected]>
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed at d3680c66 against the stacked base simonrozsival-migrate-java-dependency-verification at 3e790cab. This was a static, read-only review: I didn't build or run anything.
I covered all three changed files: JavaDependencyVerification.cs, NuGetPackageVersionFinderTests.cs and xa4248.md. I also checked the two base-branch commits after the merge-base, which include the relative-path Binding.proj fixture change.
- Central Package Management versions: an empty
Versionnow uses the restored version fromproject.assets.jsonwhen exactly one version exists. Missing, invalid or ambiguous versions report XA4248 instead of throwingArgumentExceptionor picking a version arbitrarily. Explicit versions still match with NuGet version normalization. - Precedence and diagnostics:
JavaArtifactoverrides are still applied before the version lookup, and XA4241/XA4242 reporting is unchanged. The XA4248 docs page matches the new behavior. - Tests: the new tests cover the single-version, ambiguous,
JavaArtifactprecedence and missing-dependency paths, and they assert the expected codes. - Merging with the base branch: the PR doesn't change any file-path handling, so the relative fixture inputs on the base branch behave the same with or without this change.
I found no blocking issues. I didn't run the checks the author reported.
Keep main's pipeline settings and relative-path hosting fixture while preserving the CPM fix and its five regression cases. Co-authored-by: Copilot App <[email protected]>
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
Re-reviewed at d8bc35f4 against main at 829e3fbf, after the rebase. This was a static, read-only review: I didn't build or run anything.
The three changed files (JavaDependencyVerification.cs, NuGetPackageVersionFinderTests.cs and xa4248.md) are the same as in my earlier review at d3680c66. The base is now main instead of the stacked branch, so I checked them again against what is on main: MavenExtensions.cs, Xamarin.Android.Bindings.JavaDependencyVerification.targets, the existing JavaDependencyVerificationTests and its fixtures, both project files and the XA4248 entry in the messages index. The latest main commit only bumps the external/android-api-docs submodule, which doesn't touch any of this.
- Central Package Management versions: an empty
Versionuses the restored version fromproject.assets.jsonwhen there's exactly one. Missing, invalid or ambiguous versions report XA4248 instead of throwingArgumentException. Explicit versions still match with NuGet version normalization, so projects that setVersionbehave as before. - Precedence and diagnostics:
JavaArtifactoverrides still apply before the version lookup, and XA4241/XA4242 reporting is unchanged. The XA4248 docs page and its index entry match the behavior. - Building on
main: the new code is clean under the project's nullable warnings-as-errors setting. The tests use helpers that already exist in the test project, and the targets still pass@(PackageReference)and$(ProjectAssetsFile)unchanged. - Tests: four of the new cases would throw on the old code, and they assert the exact error codes. The
JavaArtifactprecedence test guards against regressions.
One minor point that doesn't block: in a multi-targeted project, the lookup uses the assets file's libraries list, which covers all target frameworks. If different frameworks restore different versions, you get XA4248 rather than a version picked per framework. That fails safe and is documented.
I found no blocking issues. I didn't run the checks the author reported.
Fixes #10353. Originally stacked on #13470, which is now merged. This PR targets
mainand changes only the migrated Java dependency task, its tests, and the XA4248 documentation.Central Package Management leaves
PackageReference.Versionempty. Java dependency verification passed that value toNuGetVersion, which threwArgumentExceptionbefore missing Java dependencies could be reported. The reporter's attached project has this setup forMicrosoft.CodeAnalysis.BannedApiAnalyzers4.14.0.Use the restored version in
project.assets.jsonwhen the package has exactly one version. Preserve explicit version lookup andJavaArtifactoverrides. Missing, invalid, or ambiguous versions produce XA4248 instead of an exception or an arbitrary version choice. For multiple restored versions with no version metadata, the log and documentation explain how to supplyJavaArtifactmetadata.Validation on Windows with .NET SDK
12.0.100-alpha.1.26556.115:& .\eng\install-dotnet.ps1— passed; installed the branch-pinned SDK. The system .NET 11 SDK initially failed with NETSDK1045.$env:XA_REQUIRE_FULL_MSBUILD_TEST = 'true'; & .\bin\Debug\dotnet\dotnet.exe test src\Microsoft.Android.Build.Tasks\Tests\Microsoft.Android.Build.Tasks.Tests\Microsoft.Android.Build.Tasks.Tests.csproj --filter "FullyQualifiedName~NuGetPackageVersionFinderTests|FullyQualifiedName~JavaDependencyVerificationTests" -v minimal— passed after resolving the merge withmain, 31 tests with none skipped: 26 existing and five focused additions for CPM success, ambiguous-version rejection,JavaArtifactprecedence, and XA4241/XA4242 diagnostics. Existing coverage includes explicit versions, ordinary/strict multithreaded task loading, and Full MSBuild hosting.& .\bin\Debug\dotnet\dotnet.exe msbuild "$artifacts\cpm-repro\Binding.csproj" -t:Verify "-p:JavaDependencyVerificationTargets=$targets" "-p:_MicrosoftAndroidBuildTasksAssembly=$assembly" -m:2 -mt -nr:false -warnaserror:MSB4286,MSB4287,MSB4288 -v:minimalagainst the built task — confirmed emptyVersionmetadata. Before the fix: XAJDV7004/ArgumentException. After the fix: the expected XA4241 for the deliberately missing Java dependency, with no exception.git diff --check origin/main— passed.Validation used the standalone host-side task tests. A full Android SDK build, device tests, and the original Maven downloads were not run; this change does not affect runtime or Maven download code.