Skip to content

Clear AssetGroups on framework assets at P2P project boundaries#54049

Merged
javiercn merged 3 commits into
mainfrom
copilot/clear-assetgroups-on-framework-assets
May 18, 2026
Merged

Clear AssetGroups on framework assets at P2P project boundaries#54049
javiercn merged 3 commits into
mainfrom
copilot/clear-assetgroups-on-framework-assets

Conversation

Copilot AI commented Apr 22, 2026

Copy link
Copy Markdown
Contributor
  • New task ApplyStaticWebAssetFrameworkPattern that applies glob patterns to update matching SourceType=Discovered assets to SourceType=Framework
  • Register task and invoke it in ResolveProjectStaticWebAssets after DefineStaticWebAssets when StaticWebAssetFrameworkPattern is set
  • New target MaterializeProjectReferenceFrameworkAssets to materialize P2P framework assets at build time
  • New test asset FrameworkAssetsP2PConsumer for integration testing
  • Integration tests covering P2P materialization, base path rebasing, endpoint generation, and incremental builds (27 tests pass)
  • Unit tests for ApplyStaticWebAssetFrameworkPattern (9 tests pass)
  • All 684 unit tests pass
  • Fix skipped test to use Skip parameter instead of commented-out code

@javiercn javiercn marked this pull request as ready for review April 22, 2026 21:50
Copilot AI review requested due to automatic review settings April 22, 2026 21:50

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 addresses a Static Web Assets transitive behavior issue where framework assets (SourceType=Framework) incorrectly retain AssetGroups metadata across P2P boundaries, causing downstream group filtering to exclude those assets (runtime 404s).

Changes:

  • Clear AssetGroups for framework static web assets during ComputeReferenceStaticWebAssetItems execution (both single-asset and grouped-asset paths).
  • Add unit tests to verify AssetGroups clearing for framework assets and preservation for non-framework assets.
  • Extend the test helper CreateCandidate to allow specifying AssetGroups.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/StaticWebAssetsSdk/Tasks/ComputeReferenceStaticWebAssetItems.cs Adds ClearAssetGroupsIfFramework and calls it when producing referenced static web assets.
test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeReferenceStaticWebAssetItemsTest.cs Adds tests covering AssetGroups clearing behavior and updates the asset factory to set AssetGroups.
Comments suppressed due to low confidence (1)

src/StaticWebAssetsSdk/Tasks/ComputeReferenceStaticWebAssetItems.cs:66

  • In the grouped-assets branch, the decision to allow multiple assets to coexist at the same target path is based on AllAssetsHaveDistinctGroups(all, ...) before ClearAssetGroupsIfFramework runs. Clearing AssetGroups afterward can break that invariant (e.g., a framework asset becomes ungrouped while another asset at the same path keeps a non-empty group), which can later fail manifest validation (StaticWebAsset.ValidateAssetGroup treats multiple All assets at the same path without distinct non-empty groups as a conflict). Consider clearing AssetGroups before the distinct-groups check and then re-evaluating selection/coexistence (or skipping group-clearing when there are multiple assets for a target path and returning a deterministic single selection / explicit error).
                    // If all assets have distinct, non-empty AssetGroups, they can coexist
                    if (StaticWebAsset.AllAssetsHaveDistinctGroups(all, groupSet))
                    {
                        foreach (var groupedAsset in all)
                        {
                            if (ShouldIncludeAssetAsReference(groupedAsset, out var groupReason))
                            {
                                if (UpdateSourceType && !StaticWebAsset.SourceTypes.IsFramework(groupedAsset.SourceType))
                                {
                                    groupedAsset.SourceType = StaticWebAsset.SourceTypes.Project;
                                }
                                ClearAssetGroupsIfFramework(groupedAsset);
                                if (MakeReferencedAssetOriginalItemSpecAbsolute)
                                {
                                    groupedAsset.OriginalItemSpec = Path.GetFullPath(groupedAsset.OriginalItemSpec);
                                }

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @@copilot.
To learn about the PR process and branching schedule of this repo, please take a look at the SDK PR Guide.

javiercn and others added 3 commits May 18, 2026 18:59
- Extract shared MaterializeFrameworkAsset helper to StaticWebAsset
- Extract shared RemapEndpointRoute helper to StaticWebAssetEndpoint
- UpdateExternallyDefinedStaticWebAssets materializes Framework assets from
  P2P references using shared helpers
- UpdatePackageStaticWebAssets uses same shared helpers for NuGet path
- ComputeReferenceStaticWebAssetItems applies FrameworkPattern glob to mark
  matching Discovered assets as Framework
- Endpoint route remapping strips old library BasePath from routes and
  applies consumer's BasePath, including label property remapping
- OriginalFrameworkEndpoints output for correct Remove/Include contract
- RelatedAsset remapping for compressed assets during materialization
- Unit tests for materialization, pass-through, and route remapping
- P2P integration tests validating end-to-end framework asset flow

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…s clearing from ComputeReferenceStaticWebAssetItems to MaterializeFrameworkAsset, and reorder UpdateExternallyDefinedStaticWebAssets to run FilterByGroup before materialization. This prevents group-tagged framework assets (e.g. BlazorWebAssembly) from being materialized at consuming projects that don't declare acceptance of those groups.
When framework assets are materialized in the consuming project, their
compressed variants (.gz/.br) from the source library must be excluded.
The consumer's compression step regenerates them from the materialized
primary, so keeping the originals causes duplicate target path conflicts
when BasePath is '/' (as with the _framework-in-RelativePath approach).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@javiercn javiercn force-pushed the copilot/clear-assetgroups-on-framework-assets branch from 23d41c5 to a9a32c9 Compare May 18, 2026 16:59
@javiercn javiercn merged commit 7a4d7fa into main May 18, 2026
24 checks passed
@javiercn javiercn deleted the copilot/clear-assetgroups-on-framework-assets branch May 18, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, StaticWebAssetsSDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants