Skip to content

migrate FilterStaticWebAssetEndpoints - #54977

Merged
AlesProkop merged 3 commits into
dotnet:mainfrom
AlesProkop:migrate-filter-static-web-asset-endpoints
Jun 30, 2026
Merged

AlesProkop merged 3 commits into
dotnet:mainfrom
AlesProkop:migrate-filter-static-web-asset-endpoints

Conversation

@AlesProkop

Copy link
Copy Markdown
Member

Fixes dotnet/msbuild#14165

Context

MSBuild's multithreaded execution model requires tasks to avoid process-global state (current working directory). FilterStaticWebAssetEndpoints absolutized asset ContentRoot/RelatedAsset paths against the process current directory, so it would resolve them incorrectly when run on a worker thread. This migrates the task to resolve paths against its per-instance TaskEnvironment.ProjectDirectory.

Changes Made

  • Annotated FilterStaticWebAssetEndpoints with [MSBuildMultiThreadableTask] and implemented IMultiThreadableTask.
  • Added a TaskEnvironment property defaulting to TaskEnvironment.Fallback to preserve single-process semantics.
  • Passed TaskEnvironment into StaticWebAsset.ToAssetDictionary(Assets, TaskEnvironment), routing ContentRoot/RelatedAsset absolutization through env.GetAbsolutePath instead of the process current directory.
  • Left the Path.GetFullPath canonicalization wrapper in NormalizeContentRootPath intact, so dictionary keys and output paths stay canonical.

Testing

  • Built Microsoft.NET.Sdk.StaticWebAssets.Tests — 0 warnings, 0 errors.
  • Added FilterStaticWebAssetEndpointsMultiThreadingTest:
    • ResolvesRelativeContentRootAgainstTaskEnvironmentProjectDirectoryNotProcessCurrentDirectory — sets the process CWD to a decoy directory and TaskEnvironment.ProjectDirectory to a different directory, then asserts the resulting AssetsWithoutMatchingEndpoints[0] ContentRoot is rooted to the project directory, not the decoy CWD. The test fails if the migration is reverted.
    • Result: <N passed, M failed>.

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

Migrates FilterStaticWebAssetEndpoints to be safe under MSBuild’s multithreaded execution by resolving path-bearing Static Web Asset metadata (e.g., ContentRoot) against TaskEnvironment.ProjectDirectory instead of the process current working directory.

Changes:

  • Marked FilterStaticWebAssetEndpoints as [MSBuildMultiThreadableTask] and implemented IMultiThreadableTask, adding a TaskEnvironment property defaulting to TaskEnvironment.Fallback.
  • Routed asset item-group materialization through StaticWebAsset.ToAssetDictionary(Assets, TaskEnvironment) so ContentRoot/RelatedAsset normalization uses the per-task environment.
  • Added a regression test that mutates process CWD and asserts relative ContentRoot resolves against TaskEnvironment.ProjectDirectory (with assembly-wide xUnit parallelization disabled already in this test project).

Reviewed changes

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

File Description
test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FilterStaticWebAssetEndpointsMultiThreadingTest.cs Adds a regression test ensuring relative ContentRoot is absolutized using TaskEnvironment.ProjectDirectory rather than process CWD.
src/StaticWebAssetsSdk/Tasks/FilterStaticWebAssetEndpoints.cs Makes the task explicitly multi-threadable and threads TaskEnvironment into asset dictionary construction.

@jankratochvilcz jankratochvilcz 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.

Image

@AlesProkop
AlesProkop merged commit 41cb0df into dotnet:main Jun 30, 2026
25 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 1, 2026
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.

[Multithreaded] Migrate FilterStaticWebAssetEndpoints in SDK

4 participants