Skip to content

[Xamarin.Android.Build.Tasks] Replace Lint with MSBuild targets - #13500

Closed
simonrozsival wants to merge 6 commits into
mainfrom
simonrozsival-xml-impl-lint
Closed

simonrozsival wants to merge 6 commits into
mainfrom
simonrozsival-xml-impl-lint

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

The Lint task wraps tool discovery, version detection, configuration merging, and a single lint invocation. Replace its 407-line C# implementation with MSBuild targets using Exec, XmlPeek, and WriteLinesToFile, removing the task and its registration.

Preserve localized XA5205/XA0108 diagnostics, version-dependent disabled checks, Java environment options, and merged-config cleanup. Keep the three integration tests and their AndroidLintConfig wrappers, updating assertions for lint output and MSBuild severity.

Lint diagnostics now retain the original text instead of XA0102/XA0103 codes. The Exec path does not extract caret columns or remap intermediate resource paths to original source names; remove the obsolete diagnostic documentation.

Validation: git diff --check passed, and Python xml.etree.ElementTree parsing of Xamarin.Android.Common.targets and Resources.resx passed. Builds, tests, and MSBuild probes were not run, as explicitly requested.

simonrozsival and others added 3 commits November 11, 2026 14:46
Run lint and version detection with Exec, merge configurations with XmlPeek, and retain localized tooling diagnostics. Remove the task, obsolete diagnostics, and its tests.

Co-authored-by: Copilot App <[email protected]>
Restore lint diagnostic, config merging, and resource warning tests and their AndroidLintConfig wrappers. Assert raw lint output and MSBuild severity rather than legacy task error codes, and check both merged issue severities and cleanup.

Co-authored-by: Copilot App <[email protected]>
Context: 9abad42

The XML migration computes the lint config path at target execution time so it uses the final IntermediateOutputPath.  Clean needs the same initialization when invoked without Build; otherwise using the shared property would leave the config behind.

Depend on the path-initialization target from Clean and delete the config through _AndroidLintConfigFile instead of repeating its filename.  Remove the implementation details from the AndroidLintEnabled documentation as requested in review.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 13:56

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.

🟡 Changes recommended

Cached-property cleanup can leave _AndroidLintConfigFile unset and break lint-configured builds, with additional unresolved issues in incremental configuration tracking, Unix path escaping, and diagnostic severity matching.

4 open issues
1 file not reviewed
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file
What changed in this PR

Replaces the C# Lint task with MSBuild targets in the .NET for Android build pipeline.

Changes:

  • Moves lint execution, version detection, configuration merging, and Java environment setup into MSBuild.
  • Updates three integration tests for original lint output and MSBuild diagnostic severity.
  • Removes obsolete diagnostic resources and documentation, and clarifies version fallback behavior.

Validation reported in the PR is limited to diff whitespace checks and XML parsing; builds and tests were not run.

File Description
src/​Xamarin.Android.Build.Tasks/​Xamarin.Android.Common.targets Replaces task registration and invocation with lint targets and cleanup wiring.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​BuildTest.cs Updates lint output assertions and strengthens configuration-merge checks.
src/​Xamarin.Android.Build.Tasks/​Tasks/​Lint.cs Removes the C# lint task.
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.resx Removes the obsolete XA0123 message.
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.Designer.cs Removes the XA0123 resource accessor.
src/​Java.Interop.Tools.Diagnostics/​Java.Interop.Tools.Diagnostics/​Diagnostic.cs Removes comments listing XA0102 and XA0103.
Documentation/​docs-mobile/​TOC.yml Removes navigation entries for retired lint diagnostics.
Documentation/​docs-mobile/​messages/​xa0108.md Clarifies fallback version and disabled-check behavior.
Documentation/​docs-mobile/​messages/​xa0103.md Removes obsolete lint error documentation.
Documentation/​docs-mobile/​messages/​xa0102.md Removes obsolete lint warning documentation.
Documentation/​docs-mobile/​messages/​index.md Removes retired diagnostic entries and the lint task prefix.

Review effort: Balanced

simonrozsival and others added 3 commits November 11, 2026 15:11
Context: #13500

Clean runs through CallTarget when cached build properties change.  Running the lint input helper there consumes its once-per-build execution in an isolated property scope, so a later merge can lose its output path.  Initialize cleanup paths locally instead.

Record the ordered config input paths in a write-if-changed manifest so wildcard removals, additions of older files, and property-conditioned item changes invalidate the merged config without rewriting unchanged output.

Escape Unix shell metacharacters in the tool and argument values before invoking Exec.  Anchor diagnostic severity to the file/line header instead of matching Error: inside warning text.

Extend integration coverage for property-cache cleanup, config-list changes, shell-sensitive project paths, and warning text containing Error:.  Builds, tests, and MSBuild probes remain unrun at the user request; whitespace and XML syntax checks pass.

Co-authored-by: Copilot App <[email protected]>
Resolve the diagnostic prefix list by retaining both main's MDoc removal and this branch's Lint removal.

Co-authored-by: Copilot App <[email protected]>
Use POSIX single quotes instead of backslash escapes that MSBuild normalizes as path separators. Preserve lint diagnostics and accept their harmless dot path segments in the existing regression test.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • 169.254.169.254

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "169.254.169.254"

See Network Configuration for more information.

Generated by Android PR Reviewer for #13500

@github-actions github-actions Bot 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.

⚠️ Needs Changes

Findings: 1 ❌ error, 0 ⚠️ warnings, 1 💡 suggestion, posted inline. The remaining correctness issue is that merging lint XML through XmlPeek/item specifications normalizes regex backslashes on Unix, changing user suppressions. The suggestion adds positive coverage for actual lint errors.

The refactor removes the custom task cleanly, tracks config-list membership/order for incremental builds, and adds useful cleanup and warning-text regression coverage. The documented removal of XA0102/XA0103 codes, caret columns, and source-path remapping is reflected in the implementation.

CI: All 40 GitHub checks on badfe20af72f2f0777626ce9a5c8aade54211620 report success, including the aggregate dotnet-android check for Azure build 1678378. Direct Azure build-status inspection was blocked by the CLI's authentication requirement, so I could not independently verify its underlying result. Local MSBuild probes were blocked by execution permissions; the backslash finding is based on the verified MSBuild task implementation, not a local reproduction.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • 169.254.169.254

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "169.254.169.254"

See Network Configuration for more information.

Generated by Android PR Reviewer for #13500 · copilot · gpt61 · 107.6 AIC · ⌖ 4.08 AIC · ⊞ 20.2K
Comment /review to run again

Condition=" '@(AndroidLintConfig->Count())' != '0' "
Inputs="@(AndroidLintConfig);$(_AndroidLintConfigInputsFile);$(MSBuildProjectFullPath);$(MSBuildAllProjects)"
Outputs="$(_AndroidLintConfigFile)">
<XmlPeek XmlInputPath="%(AndroidLintConfig.Identity)" Query="/lint/issue" ProhibitDtd="true">

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.

🤖 ❌ MSBuild targets — XmlPeek does not preserve backslashes in these XML fragments on Linux/macOS: its Result entries are constructed with new TaskItem(...), whose default constructor normalizes backslashes to forward slashes (implementation). A valid lint configuration such as <ignore regexp="foo\s+bar" /> therefore becomes <ignore regexp="foo/s+bar" /> in the merged file. This silently changes suppression matching and can introduce lint failures that the previous XDocument merge avoided. Please merge without round-tripping XML content through path-normalized item specifications, and add a Unix regression case asserting that regex backslashes survive unchanged.

{Rule: Preserve configuration semantics across platforms.}

<Exec Command="$(_AndroidLintCommand) --quiet @(_AndroidLintArgument->'%(Switch) %(QuotedValue)', ' ')"
EnvironmentVariables="@(_AndroidLintEnvironment)"
IgnoreStandardErrorWarningFormat="true"
CustomErrorRegularExpression="^(?:(?!(?:Error|Warning):\s)(?&gt;.+?:\d+(?::\d+)?:\s*))?Error:\s"

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.

🤖 💡 Testing — Could we add a positive lint-error case for this new output parser? The updated tests all expect successful builds: they cover suppression and a real warning containing Error:, but do not establish that an actual lint Error: makes the build fail. For example, configure HardcodedText with severity error, then assert the build fails and the diagnostic contains [HardcodedText]. This would complement the warning-only regression and protect the failure behavior during future regex changes.

{Rule: Test both successful and failing diagnostic paths.}

@jonathanpeppers

Copy link
Copy Markdown
Member

Closing in favor of #13592, which removes the built-in lint support instead of rewriting the task. Thanks, @simonrozsival!

simonrozsival pushed a commit that referenced this pull request Nov 18, 2026
Context: #13500

`$(AndroidLintEnabled)` ran the Android SDK `lint` tool on the generated files in `obj/` during packaging. It was off by default, its results pointed at intermediate files instead of the project's sources, and anyone who wants `lint` can run it from the Android SDK `cmdline-tools` directly. #13500 proposed rewriting the `<Lint/>` task as MSBuild targets; removing the feature is less code to maintain.

### Removed

  * The `<Lint/>` task, its unit tests, and the `_LintChecks` target
  * `$(AndroidLintEnabledIssues)`, `$(AndroidLintDisabledIssues)`, `$(AndroidLintCheckIssues)`, `$(LintToolPath)`, and the `@(AndroidLintConfig)` item
  * `lint` discovery in `<ResolveAndroidTooling/>` and its forwarding to inner builds
  * `ResolveSdks.CommandLineToolsPath`, which only set `$(_AndroidToolsDirectory)`; nothing read that property
  * The XA0123 and XA5205_Lint resources. XA0102 and XA0103 are no longer emitted; their docs stay, marked as retired.

### Compatibility

XA0108 now warns when an app sets `$(AndroidLintEnabled)` to `true`:

```
warning XA0108: The 'AndroidLintEnabled' MSBuild property is no longer supported. Remove it. If needed, run the Android 'lint' tool directly.
```

The docs for the removed properties and item stay and say they were removed in .NET 12.

### Tests

`AndroidLintHasNoNewIssues` replaces the three lint integration tests. It builds a default app, checks for XA0108, then runs `lint --exitcode -Werror` from `cmdline-tools` on the generated manifest, resources, and Java sources. The five checks that fire today (`CustomX509TrustManager`, `HardcodedDebugMode`, `MissingApplicationIcon`, `RedundantLabel`, `UnusedResources`) are disabled, so any new `lint` issue in generated files fails the test.

The tooling-reuse tests used `$(LintToolPath)` as an escaped path; they now use `$(ZipAlignToolPath)`.
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