Skip to content

Conversation

@javiercn
Copy link
Member

Summary

Fixes a bug where GenerateStaticWebAssetsManifest fails to detect conflicting static web assets when they have different RelativePath patterns that resolve to the same target path after token replacement.

Problem

When a file in wwwroot matches the naming pattern of a scoped CSS bundle (e.g., MyApp.styles.css), the build fails with:

System.InvalidOperationException: Sequence contains more than one element
   at System.Linq.ThrowHelper.ThrowMoreThanOneElementException()
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.GenerateStaticWebAssetsDevelopmentManifest.ComputeManifestAssets()

The root cause is that GroupAssetsByTargetPath used the 2-argument ComputeTargetPath("", '/') which keeps fingerprint tokens in the path, while GenerateStaticWebAssetsDevelopmentManifest uses the 3-argument version with StaticWebAssetTokenResolver.Instance which replaces tokens.

Fix

Use StaticWebAssetTokenResolver.Instance in GroupAssetsByTargetPath to ensure consistent conflict detection.

Testing

  • Added unit tests in StaticWebAssetTest.cs to verify the fix
  • All existing GenerateStaticWebAssetsManifestTest tests pass

Use StaticWebAssetTokenResolver.Instance when computing target paths in
GroupAssetsByTargetPath to ensure assets with different RelativePath
patterns that resolve to the same path after token replacement are
correctly grouped together for conflict detection.
Copilot AI review requested due to automatic review settings December 24, 2025 14:00
@github-actions github-actions bot added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch label Dec 24, 2025
@dotnet-policy-service
Copy link
Contributor

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

@javiercn
Copy link
Member Author

Came as a side-effect of investigating #50183

@javiercn javiercn changed the title Fix duplicate asset detection in GroupAssetsByTargetPath [StaticWebAssets] Fix duplicate asset detection in GroupAssetsByTargetPath Dec 24, 2025
Copy link
Contributor

Copilot AI left a comment

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 fixes a bug in GenerateStaticWebAssetsManifest where duplicate asset detection failed when assets had different RelativePath patterns that resolved to the same target path after token replacement. The fix ensures consistent token resolution by using StaticWebAssetTokenResolver.Instance in the GroupAssetsByTargetPath method.

Key Changes

  • Updated GroupAssetsByTargetPath to use the 3-argument ComputeTargetPath overload with token resolver for consistent duplicate detection
  • Added comprehensive unit tests verifying token replacement behavior and conflict detection across different asset patterns

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetsManifest.cs Fixed GroupAssetsByTargetPath to use StaticWebAssetTokenResolver.Instance for consistent target path computation
test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetTest.cs Added comprehensive unit tests covering token replacement behavior, conflict detection, and validation of assets with different patterns resolving to the same path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants