Skip to content

Migrate UpdatePackageStaticWebAssets to IMultiThreadableTask - #54707

Merged
jankratochvilcz merged 3 commits into
dotnet:mainfrom
jankratochvilcz:mt/migrate-updatepackagestaticwebassets
Jun 18, 2026
Merged

jankratochvilcz merged 3 commits into
dotnet:mainfrom
jankratochvilcz:mt/migrate-updatepackagestaticwebassets

Conversation

@jankratochvilcz

@jankratochvilcz jankratochvilcz commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Migrates UpdatePackageStaticWebAssets (src/StaticWebAssetsSdk/Tasks/UpdatePackageStaticWebAssets.cs) to multi-threadable by adding [MSBuildMultiThreadableTask].

Fixes dotnet/msbuild#14035

Perfstar regression (14d, Windows, paired MT vs non-MT, p50 sum across iterations)

Target non-MT (ms) MT (ms) Δ (ms) Δ (%)
UpdateExistingPackageStaticWebAssets 290 4,709 +4,419 +1,524 %

Changes

  • [MSBuildMultiThreadableTask] on the concrete class. No IMultiThreadableTask plumbing needed — the task body merges existing package asset metadata into new asset items purely via dictionary lookups (no filesystem / environment / process I/O).

Compatibility sins audit (per migration skill)

24/24 dimensions clean — attribute-only opt-in.

Co-authored-by: Copilot [email protected]

@github-actions github-actions Bot added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, StaticWebAssetsSDK label Jun 11, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@jankratochvilcz

Copy link
Copy Markdown
Contributor Author

Follow-up: deeper call-stack audit (call paths into StaticWebAsset)

Tracing all helpers invoked from Execute(), one transitive call-stack hazard is shared with all SDK tasks that hydrate StaticWebAsset items:

StaticWebAsset.FromTaskItem / FromV1TaskItem → StaticWebAsset.Normalize() (instance method, src/StaticWebAssetsSdk/Tasks/Data/StaticWebAsset.cs:1067) calls:

  • NormalizeContentRootPath(ContentRoot) → Path.GetFullPath(path) (:1080)
  • Path.GetFullPath(RelatedAsset) (:1072)

Both Path.GetFullPath calls go through BCL and resolve against Environment.CurrentDirectory, not MSBuild's MT-safe AsyncLocal FileUtilities.CurrentThreadWorkingDirectory.

Why it doesn't bite in practice today: in production the SDK targets that produce these items populate ContentRoot and RelatedAsset with already-absolute paths (e.g. via MSBuild's %(FullPath) well-known modifier, which is MT-safe). Path.GetFullPath(already_absolute) becomes a pure canonicalization that doesn't read Environment.CurrentDirectory. So this PR does not introduce a regression — the latent hazard predates the migration and is exercised by every existing SWA task that consumes StaticWebAsset items.

Why not fix it here: StaticWebAsset is a data type without a TaskEnvironment reference. Plumbing one in would change a widely-used public signature and is well outside the scope of a per-task attribute / IMultiThreadableTask migration. Should be tracked as a separate follow-up.

@jankratochvilcz

Copy link
Copy Markdown
Contributor Author

No decoy-style unit test added — not viable here

This is an attribute-only opt-in. A decoy-CWD test of the form used for GenerateStaticWebAssetsManifest / MergeConfigurationProperties is not meaningful: the task body contains no File.*, Directory.*, Path.GetFullPath, Environment.* (except Environment.NewLine, a string constant), or Process.* calls whose behavior could diverge under a different process CWD. There is therefore no observable runtime behavior the migration could regress for the decoy test to catch — the attribute purely toggles whether MSBuild wraps the task in a TaskHost, which a unit test cannot exercise.

@jankratochvilcz

Copy link
Copy Markdown
Contributor Author

Failing test added (Skip = dotnet/msbuild#14036)

Added test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdatePackageStaticWebAssetsMultiThreadingTest.cs — an expected-failing test that demonstrates the latent transitive hazard from the previous comment.

What it does (decoy pattern):

  1. Real project dir at <root>/project/wwwroot/ (with site.css as the asset).
  2. Decoy CWD at <root>/decoy/spawn/ (with a parallel wwwroot directory).
  3. TaskEnvironment.CreateWithProjectDirectoryAndEnvironment(projectDir).
  4. Builds an ExistingPackageAsset with SourceType=Package, absolute Identity (real file), and relative ContentRoot="wwwroot" — the field that flows through StaticWebAsset.Normalize() -> NormalizeContentRootPath -> Path.GetFullPath.
  5. Execute(), then asserts the output ContentRoot starts with <projectDir>/wwwroot.

Locally verified (with Skip removed): the test fails with

Got     '<root>/decoy/spawn/wwwroot/'
Expected '<root>/project/wwwroot' prefix

confirming that StaticWebAsset.Normalize() resolved the relative ContentRoot against the process CWD instead of TaskEnvironment.ProjectDirectory.

The test is committed with [Fact(Skip = "https://github.com/dotnet/msbuild/issues/14036")] so CI stays green; un-skip it as part of resolving #14036.

@jankratochvilcz

Copy link
Copy Markdown
Contributor Author

Foundation PR opened: #54708 adds the TaskEnvironment overloads on StaticWebAsset. Once it merges, the next step for this PR is a one-line change in UpdatePackageStaticWebAssets.Execute to call StaticWebAsset.FromV1TaskItem(candidate, TaskEnvironment) and then un-skip UpdatePackageStaticWebAssetsMultiThreadingTest.

@jankratochvilcz
jankratochvilcz force-pushed the mt/migrate-updatepackagestaticwebassets branch 2 times, most recently from 2de1a29 to 0b19d57 Compare June 12, 2026 16:11
@jankratochvilcz
jankratochvilcz marked this pull request as ready for review June 12, 2026 16:17
Copilot AI review requested due to automatic review settings June 12, 2026 16:17

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 migrates UpdatePackageStaticWebAssets to MSBuild’s multi-threadable task model by opting in via [MSBuildMultiThreadableTask] and flowing TaskEnvironment into path normalization/materialization logic, with a focused regression test to ensure behavior does not depend on the process current working directory.

Changes:

  • Mark UpdatePackageStaticWebAssets as multi-threadable and implement IMultiThreadableTask with a TaskEnvironment property.
  • Pass TaskEnvironment through StaticWebAsset.FromV1TaskItem(...) and StaticWebAsset.MaterializeFrameworkAsset(...) to avoid process-CWD-based resolution.
  • Add a unit test that sets a “decoy” process CWD and verifies ContentRoot is normalized relative to TaskEnvironment.ProjectDirectory.

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/UpdatePackageStaticWebAssetsMultiThreadingTest.cs Adds coverage ensuring relative ContentRoot normalization is rooted in TaskEnvironment.ProjectDirectory (not process CWD).
src/StaticWebAssetsSdk/Tasks/UpdatePackageStaticWebAssets.cs Opts task into MSBuild multi-threading and threads TaskEnvironment into static web asset normalization/materialization.

@AlesProkop AlesProkop left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I would just trim some of the commentary as it seems quite verbose. If you do not agree, I am ok with merging as is.

Jan Kratochvil and others added 3 commits June 17, 2026 10:50
Marks the task with [MSBuildMultiThreadableTask] so MSBuild's multithreaded mode skips the per-task TaskHost wrapper. The task body merges package asset metadata purely in memory, so attribute-only opt-in is sufficient per the migration skill.

Co-authored-by: Copilot <[email protected]>
…(Skip referencing dotnet/msbuild#14036)

Demonstrates the transitive call-stack hazard: StaticWebAsset.FromV1TaskItem -> Normalize() -> Path.GetFullPath(ContentRoot) leaks the process CWD into output ContentRoot when ContentRoot is supplied as a relative path. The test is marked Skip because the per-task migration cannot fix the StaticWebAsset data type; tracking dotnet/msbuild#14036. Locally verified that removing the Skip causes a clean assertion failure pointing at the decoy CWD.

Co-authored-by: Copilot <[email protected]>
- Shorten class-level comment to one line
- Remove duplicate inline comment on ContentRoot metadata
- Use .Be(projectContentRoot + DirectorySeparatorChar) for stricter assertion

Co-authored-by: Copilot <[email protected]>
@jankratochvilcz
jankratochvilcz force-pushed the mt/migrate-updatepackagestaticwebassets branch from 45e14cb to 17466f7 Compare June 17, 2026 08:50

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

:shipit:

@jankratochvilcz

Copy link
Copy Markdown
Contributor Author

/azp run dotnet-sdk-public-ci

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@jankratochvilcz
jankratochvilcz enabled auto-merge (squash) June 18, 2026 13:29
@jankratochvilcz
jankratochvilcz merged commit 09220af into dotnet:main Jun 18, 2026
25 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
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.

[Multithreaded] Migrate UpdatePackageStaticWebAssets in SDK

4 participants