Skip to content

[Extensibility] Fix dual-path backend activation and Compile bucket filtering - #36956

Closed
PureWeen wants to merge 1 commit into
net11.0from
pureween-fix-backend-msbuild-gaps
Closed

[Extensibility] Fix dual-path backend activation and Compile bucket filtering#36956
PureWeen wants to merge 1 commit into
net11.0from
pureween-fix-backend-msbuild-gaps

Conversation

@PureWeen

@PureWeen PureWeen commented Jul 30, 2026

Copy link
Copy Markdown
Member

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

This is a focused follow-up to #36654 from GPT-5.6 Sol post-merge verification. It addresses two gaps in the data-driven MauiPlatformSpecificFolder implementation related to #34099.

  • Enables one backend registration to activate through either a recognized TargetPlatformIdentifiers match or neutral-TFM MauiActiveBackend selection.
  • Prevents the platform Compile removal batch from capturing explicit-false Compile items that happen to exist on disk beside an explicit-true item.

Root causes and behavior

Dual-path backend activation

_MauiNormalizePlatformSpecificFolders previously derived ActivationValue from BackendIdentity only when both singular and plural TPI metadata were empty. A registration such as TargetPlatformIdentifiers="macos" BackendIdentity="macos" therefore worked for a recognized macOS TPI but could not use MauiActiveBackend=macos on a neutral TFM.

The normalization now derives the default whenever ActivationValue is empty, regardless of TPI metadata. Explicit ActivationValue and ActivationProperty values remain untouched. The existing recognized-TPI guard still prevents a neutral selector from over-activating the backend on another recognized TPI.

Compile metadata bucket isolation

_MauiRemovePlatformCompileItems batched on %(Compile.ExcludeFromCurrentConfiguration) but created each batch from a fresh filesystem glob. In the true batch, that glob also discovered physical Compile files belonging to a separate explicit-false metadata bucket, allowing the false item to be removed unless it was separately allow-listed.

Removal candidates now originate from the batched @(Compile) identities and are narrowed to $(PlatformsProjectFolder). Allow-list matching remains path-like, and the operation does not mutate or reorder surviving Compile items.

Tests

Added shipping-target regression coverage in MSBuildTests for:

  • one macos registration activating through recognized TPI and neutral MauiActiveBackend paths;
  • negative recognized-TPI and nonmatching-backend cases;
  • explicit-false and explicit-true physical Compile files without an allow-list, asserting only the true item is removed;
  • surviving metadata, ordering, and duplicate count;
  • explicit custom activation semantics on a registration that also has TPI metadata.

Validation performed:

  • Both new minimal repros fail against merge ff48f228 and pass with this change.
  • Workload-neutral real shipping-target matrix passed for legacy shared folders, all built-in mappings, GTK/backend activation, custom activation properties, whitespace/unresolved metadata, bare-ActivationValue compatibility, design-time unflip, ordering, and duplicate counts.
  • Target XML validation, diff whitespace validation, and targeted dotnet format --verify-no-changes passed.

The full Controls.Xaml.UnitTests invocation could not run locally because restoring Microsoft.Maui.BuildTasks.slnf requires the unavailable iOS workload (NETSDK1147). The same shipping targets were therefore exercised directly with the repository-pinned .NET 11 SDK and workload-neutral net10.0 repro projects.

Issues Fixed

Related to #34099.
Follow-up to #36654.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ac6265fe-09a0-473c-b3f9-9ec6d6dd97cd
Copilot AI review requested due to automatic review settings July 30, 2026 20:08
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 30, 2026 20:08 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36956

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36956"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 30, 2026 20:08 — with GitHub Actions Inactive
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 30, 2026 20:10 — with GitHub Actions Inactive
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 30, 2026 20:12 — with GitHub Actions Inactive
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 30, 2026 20:13 — with GitHub Actions Inactive
@github-actions github-actions Bot added the area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer label Jul 30, 2026
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 30, 2026 20:14 — with GitHub Actions Inactive

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.

Pull request overview

This PR tightens .NET MAUI SingleProject MSBuild extensibility for third-party backends by (1) allowing a single backend registration to activate through either recognized TPI matching or neutral-TFM backend selection, and (2) fixing _MauiRemovePlatformCompileItems so its removal batching can’t incorrectly remove Compile items from other metadata buckets.

Changes:

  • Default ActivationValue from BackendIdentity even when TargetPlatformIdentifier(s) metadata is present, enabling dual-path activation.
  • Rework _MauiRemovePlatformCompileItems to root removal candidates in the batched @(Compile) identities (instead of a fresh filesystem glob) and then narrow to $(PlatformsProjectFolder).
  • Add MSBuild unit test coverage for the compile-removal bucket isolation regression and for dual-path backend activation.
Show a summary per file
File Description
src/Controls/tests/Xaml.UnitTests/MSBuild/MSBuildTests.cs Adds regression tests covering compile-removal bucket isolation and dual-path backend activation behavior.
src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.targets Fixes compile removal candidate selection to respect cross-item-type batching buckets and avoid filesystem-glob cross-contamination.
src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.Before.targets Updates backend activation defaulting logic so one registration can activate via recognized TPI or neutral MauiActiveBackend.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

<MauiPlatformSpecificFolder
Update="@(MauiPlatformSpecificFolder)"
Condition=" '%(MauiPlatformSpecificFolder.ActivationValue)' == '' and '%(MauiPlatformSpecificFolder.BackendIdentity)' != '' and '%(MauiPlatformSpecificFolder.TargetPlatformIdentifier)' == '' and '%(MauiPlatformSpecificFolder.TargetPlatformIdentifiers)' == '' ">
Condition=" '%(MauiPlatformSpecificFolder.ActivationValue)' == '' and '%(MauiPlatformSpecificFolder.BackendIdentity)' != '' ">
@kubaflo

kubaflo commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Closing in favor of #36957. Main build 1533723 fails the PR-added SingleProject_RemovePlatformCompileItems_RemovesOnlyCompileItemsMarkedTrue test on every Windows Helix XAML leg: the explicit-false marker is removed. #36957 is the selected implementation and carries the final expanded coverage.

@kubaflo kubaflo closed this Jul 30, 2026
kubaflo pushed a commit that referenced this pull request Jul 31, 2026
…ompile filtering (#36957)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

## Description of Change

This focused follow-up addresses two empirically validated gaps found by
the GPT-5.6 Sol post-merge verification of #36654.

1. `BackendIdentity` now defaults `ActivationValue` even when
`TargetPlatformIdentifier` or `TargetPlatformIdentifiers` is also
present. A single registration can therefore activate through a
recognized TPI or through `MauiActiveBackend` on a neutral TFM, while
explicit `ActivationValue` and `ActivationProperty` metadata still win.
2. platform Compile removal now starts from the `Compile` items in the
`ExcludeFromCurrentConfiguration=true` metadata batch and intersects
them with physical `Platforms/**` candidates. A fresh filesystem glob
can no longer pull an explicitly false Compile item from another
metadata bucket into the removal set. The helper-item removal pattern
remains in place, preserving active item order and avoiding
remove/re-add duplication.

## Before and After

Before this change, a registration such as:

```xml
<MauiPlatformSpecificFolder Include="Platforms/MacOS/" TargetPlatformIdentifiers="macos" BackendIdentity="macos" />
```

worked for recognized TPI `macos` but did not activate on a neutral TFM
with `MauiActiveBackend=macos`. It now supports both paths and remains
inactive for another recognized TPI or a mismatched backend.

Before this change, the presence of any true Compile metadata batch
caused a fresh `Platforms/**` glob to include physical files explicitly
marked false by a downstream target. Removal is now constrained to the
actual true Compile identities under the platform folder.

## Tests

The real shipping SingleProject targets are covered by regressions for:

- one dual-path macOS registration through recognized TPI and neutral
backend activation, plus recognized-TPI and backend mismatch negatives;
- two physical platform Compile files in different metadata buckets with
no folder allow-list, asserting only the true item is removed and the
surviving list is ordered and duplicate-free.

Validation:

- complete `MSBuildTests.SingleProject_*` matrix: **46 passed, 0
failed**;
- new regression matrix: **7 passed, 0 failed**;
- `Controls.Build.Tasks.csproj` build: **succeeded with 0 warnings and 0
errors**;
- targeted `dotnet format`: completed successfully.

The unfiltered local graph is unavailable on this Mac because the
platform project graph requires the iOS workload (`NETSDK1147`) and the
full BuildTasks solution filter includes .NET Framework 4.7.2 projects
without local reference assemblies (`MSB3644`). The workload-neutral
matrix above used the repository-pinned .NET 11 SDK with platform TFMs
disabled and imported the exact shipping targets.

### Candidate selection and final review

#36957 is the selected implementation. Alternatives #36955 and #36956
both fail their own new Windows Helix XAML regression by removing the
explicit-false Compile item. This branch uses FullPath/PathLike
intersection, passes the expanded 46-case matrix, preserves metadata and
duplicate count, handles absolute Compile identities, and skips the
platform filesystem glob when no removal batch exists.

Neutral activation of built-in backend identities is intentional: #36654
documented that built-ins use the same registration shape and that
ActivationValue defaults from BackendIdentity. A dedicated regression
now locks that contract.

## Issues Fixed

Part of #34099
Part of #35021
Fixes #36650
Follow-up to #36654

---------

Co-authored-by: PureWeen <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ac6265fe-09a0-473c-b3f9-9ec6d6dd97cd
Copilot-Session: 66f84348-6476-4097-8b7f-f240338e85c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants