Skip to content

Migrate DefineStaticWebAssets to multithreaded task execution#55117

Open
AlesProkop wants to merge 1 commit into
dotnet:mainfrom
AlesProkop:migrate-define-static-web-assets
Open

Migrate DefineStaticWebAssets to multithreaded task execution#55117
AlesProkop wants to merge 1 commit into
dotnet:mainfrom
AlesProkop:migrate-define-static-web-assets

Conversation

@AlesProkop

@AlesProkop AlesProkop commented Jul 2, 2026

Copy link
Copy Markdown
Member

Fixes: dotnet/msbuild#14040

Context

DefineStaticWebAssets now participates in MSBuild multithreaded task execution. Relative candidate paths, content roots, cache manifest paths, and cache input keys must resolve against TaskEnvironment.ProjectDirectory instead of the process current directory.

Changes Made

  • Added [MSBuildMultiThreadableTask], IMultiThreadableTask, and TaskEnvironment support to DefineStaticWebAssets.
  • Plumbed TaskEnvironment through StaticWebAsset.FromProperties, normalization, file resolution, and related content-root handling.
  • Absolutized CacheManifestPath relative to TaskEnvironment.ProjectDirectory.
  • Updated DefineStaticWebAssets cache input hashing to avoid CWD-sensitive FullPath and ModifiedTime metadata, hashing MT-safe candidate paths and file state instead.
  • Added DefineStaticWebAssetsMultiThreadingTest coverage for relative candidate/content-root resolution and cache invalidation under a decoy process CWD.

Testing

  • dotnet build src/StaticWebAssetsSdk/Tasks/Microsoft.NET.Sdk.StaticWebAssets.Tasks.csproj — passed for net11.0 and net472.
  • dotnet test test/Microsoft.NET.Sdk.StaticWebAssets.Tests/Microsoft.NET.Sdk.StaticWebAssets.Tests.csproj --filter "FullyQualifiedName~DefineStaticWebAssetsMultiThreadingTest" — passed, 2 tests.

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 DefineStaticWebAssets to MSBuild multithreaded task execution by routing all path resolution through TaskEnvironment.ProjectDirectory (instead of process CWD) and updating related Static Web Assets normalization + cache invalidation behavior.

Changes:

  • Marked DefineStaticWebAssets as [MSBuildMultiThreadableTask] and added IMultiThreadableTask/TaskEnvironment plumbing for MT-safe path resolution.
  • Updated Static Web Asset normalization/file resolution APIs to accept a TaskEnvironment so relative paths resolve against the project directory.
  • Reworked cache manifest path absolutization and cache input hashing to avoid CWD-sensitive metadata, adding MT-focused test coverage.

Reviewed changes

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

File Description
test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DefineStaticWebAssetsMultiThreadingTest.cs Adds tests validating MT-safe resolution against TaskEnvironment.ProjectDirectory and cache invalidation under a decoy process CWD.
src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssets.cs Switches candidate identity/content-root handling to use TaskEnvironment and MT-safe file resolution.
src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssets.Cache.cs Absolutizes cache manifest path via TaskEnvironment and updates cache input hashing to be MT/CWD independent.
src/StaticWebAssetsSdk/Tasks/Data/StaticWebAsset.cs Extends asset construction/normalization to accept TaskEnvironment (fallback preserved for existing callers).

Comment on lines +20 to 24
var cacheManifestPath = string.IsNullOrEmpty(CacheManifestPath)
? CacheManifestPath
: TaskEnvironment.GetAbsolutePath(CacheManifestPath).Value;
var assetsCache = DefineStaticWebAssetsCache.ReadOrCreateCache(Log, cacheManifestPath);
if (CacheManifestPath == null)
}

[TestMethod]
public void CacheInvalidatesRelativeCandidateWhenProjectFileChanges_NotProcessCurrentDirectory()
if (Path.IsPathRooted(candidateMatchPath) && candidateMatchPath == candidate.ItemSpec)
{
var normalizedAssetPath = Path.GetFullPath(candidate.GetMetadata("FullPath"));
var normalizedAssetPath = Path.GetFullPath(TaskEnvironment.GetAbsolutePath(candidate.ItemSpec));

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.

Will it not be the same as candidate.GetMetadata("FullPath") ?

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 DefineStaticWebAssets in SDK

3 participants