Migrate GenerateStaticWebAssetsManifest to IMultiThreadableTask - #54704
#54704Migrate GenerateStaticWebAssetsManifest to IMultiThreadableTask#54704jankratochvilcz merged 9 commits intodotnet:maindotnet/sdk:mainfrom jankratochvilcz:mt/migrate-generate-static-web-assets-manifestjankratochvilcz/sdk:mt/migrate-generate-static-web-assets-manifestCopy head branch name to clipboard
Conversation
Follow-up: deeper call-stack audit (call paths into StaticWebAsset)Tracing all helpers invoked from
Both Why it doesn't bite in practice today: in production the SDK targets that produce these items populate Why not fix it here: |
afeb601 to
07808d9
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates GenerateStaticWebAssetsManifest to MSBuild’s IMultiThreadableTask pattern so multithreaded builds can run the task in-proc (avoiding TaskHost overhead) while ensuring relative path I/O is rooted at TaskEnvironment.ProjectDirectory rather than the process CWD.
Changes:
- Marked
GenerateStaticWebAssetsManifestas[MSBuildMultiThreadableTask], implementedIMultiThreadableTask, and added aTaskEnvironmentproperty defaulting toTaskEnvironment.Fallback. - Updated
PersistManifestto absolutizeManifestPath/ManifestCacheFilePathonce viaTaskEnvironment.GetAbsolutePath(...)and use those absolute paths for all file I/O. - Added a new test that mutates the process current directory to validate the task writes under
TaskEnvironment.ProjectDirectory.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetsManifest.cs | Converts the task to IMultiThreadableTask and routes manifest/cache file I/O through TaskEnvironment-anchored absolute paths. |
| test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsManifestMultiThreadingTest.cs | Adds coverage ensuring relative manifest paths resolve against TaskEnvironment.ProjectDirectory, not the process CWD. |
- Add [MSBuildMultiThreadableTask] attribute and IMultiThreadableTask - Absolutize ManifestPath and ManifestCacheFilePath via TaskEnvironment - Pass TaskEnvironment to StaticWebAsset.FromTaskItemGroup - Add decoy-CWD test (Pattern A) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Match the defensive pattern used elsewhere in StaticWebAsset (e.g., NormalizeContentRootPath, ResolveFile) — skip absolutization when the input is null or empty instead of letting GetAbsolutePath throw. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4aecac5 to
4099d77
Compare
Address self-review comments: - manifestPath -> absolutizedManifestPath - hasCacheFile -> isManifestCacheFileConfigured - manifestCachePath -> absolutizedManifestCacheFilePath - fileExists -> manifestFileExists Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The conditional expression is typed as string and cannot implicitly convert to AbsolutePath. Declare the locals as string, matching other migrated tasks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This test file was added on main by dotnet#54704 after this branch migrated Microsoft.NET.Sdk.StaticWebAssets.Tests to MSTest.Sdk, so the merge reintroduced xUnit [Fact] usage that no longer compiles (CS0246 FactAttribute/Fact). Convert it to [TestClass]/[TestMethod] with [DoNotParallelize], matching the sibling MultiThreading tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Migrates
GenerateStaticWebAssetsManifest(src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetsManifest.cs) toIMultiThreadableTaskso MSBuild's multithreaded mode bypasses the per-task TaskHost wrapper.Fixes dotnet/msbuild#14032
Perfstar regression (14d, Windows, paired MT vs non-MT, p50 sum across iterations)
GenerateStaticWebAssetsManifestChanges
[MSBuildMultiThreadableTask]+ implementsIMultiThreadableTaskwith defaultTaskEnvironment.Fallback.PersistManifest,ManifestPathand (optional)ManifestCacheFilePathare absolutized once at the top viaTaskEnvironment.GetAbsolutePath. All subsequentFile.Exists/File.ReadAllBytes/File.WriteAllBytes/File.WriteAllTextcalls use the absolutized values. Log messages continue to use the original user-provided property values.Compatibility sins audit (per migration skill)
[Output]property on this task.ManifestPath/ManifestCacheFilePathstrings.??swallowing exceptions): no new null-coalescing.PersistManifesthas no try/catch.GetAbsolutePath("")throwsArgumentException.ManifestPathis[Required]so MSBuild rejects empty values upstream. The optionalManifestCacheFilePathis guarded bystring.IsNullOrEmptybefore callingGetAbsolutePath.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com