Skip to content

Migrate Tlblmp to Multithreaded Execution#13708

Open
AlesProkop wants to merge 1 commit intodotnet:mainfrom
AlesProkop:migrate-tlblmp-to-multithreaded
Open

Migrate Tlblmp to Multithreaded Execution#13708
AlesProkop wants to merge 1 commit intodotnet:mainfrom
AlesProkop:migrate-tlblmp-to-multithreaded

Conversation

@AlesProkop
Copy link
Copy Markdown
Member

@AlesProkop AlesProkop commented May 7, 2026

Fixes #13633

Context

TlbImp is a nested ToolTask used by ResolveComReference to wrap TlbImp.exe. Its process invocation and path
resolution relied on global process state, blocking safe parallel execution under MSBuild's multithreaded task
model.

Changes Made

  • Annotated TlbImp with [MSBuildMultiThreadableTask] and implemented IMultiThreadableTask on the shared
    AxTlbBaseTask (covers AxImp too).
  • Routed path inputs (TypeLibName, AssemblyFile/OutputAssembly, KeyFile, ReferenceFiles, ToolPath) through
    TaskEnvironment.GetAbsolutePath(), without leaking into [Output] properties.
  • Switched process launch to TaskEnvironment.GetProcessStartInfo() and env reads to
    TaskEnvironment.GetEnvironmentVariable().
  • Propagated TaskEnvironment from ResolveComReference into the nested invocations.

Testing

  • Existing ResolveComReference / TlbImp / AxImp tests pass.
  • Clean build, no new warnings.

@AlesProkop AlesProkop changed the title migrate tlblmp [DRAFT, DNR] Migrate Tlblmp to Multithreaded Execution May 7, 2026
@AlesProkop AlesProkop marked this pull request as ready for review May 7, 2026 12:24
Copilot AI review requested due to automatic review settings May 7, 2026 12:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 aims to make the COM interop wrapper ToolTasks (notably the nested ResolveComReference.TlbImp, via shared AxTlbBaseTask) safe under MSBuild’s multithreaded task execution model by removing reliance on global process state for path handling.

Changes:

  • Marked ResolveComReference.TlbImp as [MSBuildMultiThreadableTask] and updated its command-line generation to absolutize key path inputs via TaskEnvironment.GetAbsolutePath().
  • Updated AxTlbBaseTask to validate/tool-resolve using TaskEnvironment-based absolute paths (ToolPath/SdkToolsPath/KeyFile).
  • Updated unit tests to assert the new absolutized command-line arguments.

Reviewed changes

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

File Description
src/Tasks/TlbImp.cs Adds multithreadable annotation and absolutizes TypeLibName/OutputAssembly/ReferenceFiles in generated command line.
src/Tasks/AxTlbBaseTask.cs Absolutizes tool path resolution and strong-name key file handling/validation using TaskEnvironment.
src/Tasks.UnitTests/TlbImp_Tests.cs Updates expectations to match absolutized /reference, TypeLibName, and /out: arguments.
src/Tasks.UnitTests/AxTlbBaseTask_Tests.cs Updates /keyfile: expectation to match absolutized KeyFile argument.

Comment on lines +110 to +112
f => string.IsNullOrEmpty(f)
? SdkToolsPathUtility.FileInfoExists(f)
: SdkToolsPathUtility.FileInfoExists(TaskEnvironment.GetAbsolutePath(f)),
Comment on lines 41 to 49
t.ReferenceFiles = new string[] { "File1.dll", "File2.dll" };
CommandLine.ValidateHasParameter(
t,
"/reference:File1.dll",
"/reference:" + Path.GetFullPath("File1.dll"),
false /* no response file */);
CommandLine.ValidateHasParameter(
t,
"/reference:File2.dll",
"/reference:" + Path.GetFullPath("File2.dll"),
false /* no response file */);
Comment thread src/Tasks/TlbImp.cs
Comment on lines 239 to 244
protected internal override void AddCommandLineCommands(CommandLineBuilderExtension commandLine)
{
// .ocx file being imported
commandLine.AppendFileNameIfNotNull(TypeLibName);
commandLine.AppendFileNameIfNotNull(AbsolutizeIfNotEmpty(TypeLibName));

// options
// throw an error.
//
// So use /publickey if that's all our KeyFile contains, but KeyFile otherwise.
string absoluteKeyFile = string.IsNullOrEmpty(KeyFile) ? KeyFile : TaskEnvironment.GetAbsolutePath(KeyFile).Value;
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.

does this really make sense?
I thought that for these tool tasks it's correct to give them the relative parameters, because their processes are spawned at the correct CWD (handled by ToolTask)

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.

Migrate TlbImp to multithreaded execution

3 participants