From 84518fb162b179a0b277de874a8c53654b760008 Mon Sep 17 00:00:00 2001 From: "Jan Krivanek (via Copilot)" Date: Tue, 28 Apr 2026 07:59:01 +0200 Subject: [PATCH] Migrate CreateCSharpManifestResourceName and CreateVisualBasicManifestResourceName to multithreaded execution Adds [MSBuildMultiThreadableTask] to both concrete classes and routes file I/O through TaskEnvironment.GetAbsolutePath in the shared CreateManifestResourceName base. Subscribes the base class to IMultiThreadableTask with a TaskEnvironment.Fallback default. Closes part of #13172. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Tasks/CreateCSharpManifestResourceName.cs | 1 + src/Tasks/CreateManifestResourceName.cs | 14 +++++++++++--- src/Tasks/CreateVisualBasicManifestResourceName.cs | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Tasks/CreateCSharpManifestResourceName.cs b/src/Tasks/CreateCSharpManifestResourceName.cs index c7f838b16ef..a674351db1c 100644 --- a/src/Tasks/CreateCSharpManifestResourceName.cs +++ b/src/Tasks/CreateCSharpManifestResourceName.cs @@ -16,6 +16,7 @@ namespace Microsoft.Build.Tasks /// Base class for task that determines the appropriate manifest resource name to /// assign to a given resx or other resource. /// + [MSBuildMultiThreadableTask] public class CreateCSharpManifestResourceName : CreateManifestResourceName { protected override string SourceFileExtension => ".cs"; diff --git a/src/Tasks/CreateManifestResourceName.cs b/src/Tasks/CreateManifestResourceName.cs index 99e71de2b07..65e3acac6e9 100644 --- a/src/Tasks/CreateManifestResourceName.cs +++ b/src/Tasks/CreateManifestResourceName.cs @@ -20,8 +20,15 @@ namespace Microsoft.Build.Tasks /// Base class for task that determines the appropriate manifest resource name to /// assign to a given resx or other resource. /// - public abstract class CreateManifestResourceName : TaskExtension + public abstract class CreateManifestResourceName : TaskExtension, IMultiThreadableTask { + /// + /// The task environment used for thread-safe file system access. Set by MSBuild for + /// multithreaded execution; defaults to a process-wide fallback for legacy hosting. + /// + public TaskEnvironment TaskEnvironment { get; set; } = TaskEnvironment.Fallback; + + #region Properties internal const string resxFileExtension = ".resx"; internal const string restextFileExtension = ".restext"; @@ -190,7 +197,8 @@ internal bool Execute( } } - if (FileSystems.Default.FileExists(Path.Combine(Path.GetDirectoryName(fileName), conventionDependentUpon))) + string conventionProbePath = Path.Combine(Path.GetDirectoryName(fileName), conventionDependentUpon); + if (FileSystems.Default.FileExists(TaskEnvironment.GetAbsolutePath(conventionProbePath))) { dependentUpon = conventionDependentUpon; } @@ -215,7 +223,7 @@ internal bool Execute( if (isDependentOnSourceFile) { string pathToDependent = Path.Combine(Path.GetDirectoryName(fileName), dependentUpon); - binaryStream = createFileStream(pathToDependent, FileMode.Open, FileAccess.Read); + binaryStream = createFileStream(TaskEnvironment.GetAbsolutePath(pathToDependent), FileMode.Open, FileAccess.Read); } // Put the task item into a dictionary so we can access it from a derived class quickly. diff --git a/src/Tasks/CreateVisualBasicManifestResourceName.cs b/src/Tasks/CreateVisualBasicManifestResourceName.cs index d2cf7f405ef..40c0224dc8c 100644 --- a/src/Tasks/CreateVisualBasicManifestResourceName.cs +++ b/src/Tasks/CreateVisualBasicManifestResourceName.cs @@ -15,6 +15,7 @@ namespace Microsoft.Build.Tasks /// Base class for task that determines the appropriate manifest resource name to /// assign to a given resx or other resource. /// + [MSBuildMultiThreadableTask] public class CreateVisualBasicManifestResourceName : CreateManifestResourceName { protected override string SourceFileExtension => ".vb";