Skip to content

Migrate ConcatenateCssFiles - #55002

Merged
AlesProkop merged 5 commits into
dotnet:mainfrom
AlesProkop:migrate-concate-css-files
Jul 1, 2026
Merged

AlesProkop merged 5 commits into
dotnet:mainfrom
AlesProkop:migrate-concate-css-files

Conversation

@AlesProkop

Copy link
Copy Markdown
Member

Fixes dotnet/msbuild#14169

Context

Migrates the ConcatenateCssFiles MSBuild task to the multithreaded execution model. The task reads scoped-css inputs and writes the bundle to disk, so it must resolve every path against the task's own project directory via TaskEnvironment instead of relying on the process-global current directory that the shared multithreaded host no longer guarantees.

Changes Made

  • Added [MSBuildMultiThreadableTask] and implemented IMultiThreadableTask on ConcatenateCssFiles.
  • Added the TaskEnvironment property defaulting to TaskEnvironment.Fallback.
  • Absolutized the input read: File.ReadLines(current.GetMetadata("FullPath")) is now File.ReadLines(TaskEnvironment.GetAbsolutePath(current.ItemSpec)).
  • Absolutized the output path once into outputFile = TaskEnvironment.GetAbsolutePath(OutputFile) and routed File.Exists, SameContent, Directory.CreateDirectory, and File.WriteAllText through it.

Testing

  • Built Microsoft.NET.Sdk.StaticWebAssets.Tasks.csproj (net11.0 and net472) with the dotnet/msbuild Microsoft.Build.TaskAuthoring.Analyzer temporarily injected; ConcatenateCssFiles.cs compiles and the analyzer surfaces only one MSBuildTask0003 (the SameContent read — a false positive, see Notes).
  • Added ConcatenateCssFilesMultiThreadingTest in Microsoft.NET.Sdk.StaticWebAssets.Tests:
    • ReadsInputsAndWritesBundleRelativeToTaskEnvironmentProjectDirectory_NotProcessCurrentDirectory

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 the ConcatenateCssFiles Static Web Assets MSBuild task to MSBuild’s multi-threaded task execution model by introducing TaskEnvironment-rooted path resolution, and adds a regression test to ensure behavior is independent of the process current working directory.

Changes:

  • Marked ConcatenateCssFiles as [MSBuildMultiThreadableTask], implemented IMultiThreadableTask, and introduced a TaskEnvironment property.
  • Updated input and output file IO to resolve paths via TaskEnvironment.GetAbsolutePath(...) rather than relying on process CWD.
  • Added a multi-threading regression test validating input reads and output writes are rooted in 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/ConcatenateCssFilesMultiThreadingTest.cs Adds a regression test to verify bundling behavior is independent of the process current directory.
src/StaticWebAssetsSdk/Tasks/ScopedCss/ConcatenateCssFiles.cs Makes the task multi-threadable and updates IO to use TaskEnvironment for path resolution.
Comments suppressed due to low confidence (1)

src/StaticWebAssetsSdk/Tasks/ScopedCss/ConcatenateCssFiles.cs:18

  • The task still sorts ScopedCssFiles/ProjectBundles using GetMetadata("FullPath"). In this task invocation, FullPath isn’t materialized by MSBuild (items are passed without %(FullPath)), so TaskItem.GetMetadata("FullPath") will be computed at task runtime and can still be rooted in the process current directory. That undermines the MT-host migration goal and can make bundle ordering depend on CWD. Consider sorting by ItemSpec (or by a TaskEnvironment-rooted absolute path) instead of FullPath.
public class ConcatenateCssFiles : Task, IMultiThreadableTask
{
    private static readonly char[] _separator = ['/'];

    private static readonly IComparer<ITaskItem> _fullPathComparer =

@AlesProkop
AlesProkop enabled auto-merge (squash) July 1, 2026 07:12
@AlesProkop
AlesProkop merged commit 1ebc857 into dotnet:main Jul 1, 2026
25 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 6, 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 ConcatenateCssFiles in SDK

4 participants