Skip to content

Migrate Tlblmp and AxImp to Multithreaded Execution#13708

Open
AlesProkop wants to merge 14 commits into
dotnet:mainfrom
AlesProkop:migrate-tlblmp-to-multithreaded
Open

Migrate Tlblmp and AxImp to Multithreaded Execution#13708
AlesProkop wants to merge 14 commits into
dotnet:mainfrom
AlesProkop:migrate-tlblmp-to-multithreaded

Conversation

@AlesProkop
Copy link
Copy Markdown
Member

@AlesProkop AlesProkop commented May 7, 2026

Fixes #13633
Fixes #13626

Context

TlbImp is an internal nested ToolTask used by ResolveComReference to wrap TlbImp.exe. This change marks the concrete TlbImp task as safe for MSBuild's multithreaded task model and audits the shared AxTlbBaseTask base class used by both TlbImp and AxImp.

Changes Made

  • Annotated TlbImp with [MSBuildMultiThreadableTask].

  • Annotated AxImp with [MSBuildMultiThreadableTask], since it is the other concrete task derived from AxTlbBaseTask.

  • Audited AxTlbBaseTask and routed file-system checks through TaskEnvironment.GetAbsolutePath() for:

    • ToolPath
    • SdkToolsPath
    • KeyFile
  • Kept tool command-line path arguments verbatim intentionally:

    • TypeLibName
    • OutputAssembly
    • ReferenceFiles
    • ActiveXControlName
    • RuntimeCallableWrapperAssembly
    • KeyFile when passed to TlbImp.exe / AxImp.exe

    These are resolved by the spawned tool relative to the task environment working directory provided by ToolTask, avoiding user-visible path inflation.

  • Did not migrate ResolveComReference itself in this PR. That task is broader and AppDomain/current-directory/cache-path sensitive, so it should be handled separately.

Notes

IMultiThreadableTask, TaskEnvironment, process launch via TaskEnvironment.GetProcessStartInfo(), and task environment variable handling are provided by the shared ToolTask base infrastructure.

Testing

  • Built src\Tasks\Microsoft.Build.Tasks.csproj successfully.
  • Ran focused GetAssemblyIdentity tests:
    • Microsoft.Build.Tasks.UnitTests.exe --filter-class Microsoft.Build.UnitTests.GetAssemblyIdentity_Tests --no-progress
    • Result: 9 passed, 0 failed

@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 thread src/Tasks/AxTlbBaseTask.cs Outdated
Comment thread src/Tasks.UnitTests/TlbImp_Tests.cs
Comment thread src/Tasks/TlbImp.cs
Comment thread src/Tasks/AxTlbBaseTask.cs Outdated
@AlesProkop AlesProkop requested a review from JanProvaznik May 12, 2026 07:23
Comment thread src/Tasks/TlbImp.cs Outdated
Comment thread src/Tasks/TlbReference.cs
@AlesProkop AlesProkop requested a review from AR-May May 13, 2026 13:53
@AlesProkop
Copy link
Copy Markdown
Member Author

AlesProkop commented May 13, 2026

Reversed some changes. I am not sure about the scope of this ticket. @AR-May please, could you specify what exactly has to be migrated? (There are two classes depending on this one, and there is also ResolveComReference)

@AR-May
Copy link
Copy Markdown
Member

AR-May commented May 13, 2026

Reversed some changes. I am not sure about the scope of this ticket. @AR-May please, could you specify what exactly has to be migrated? (There are two classes depending on this one, and there is also ResolveComReference)

@AlesProkop I would suggest to enlighten both derived classes. There is no need to do it in separate pr, as those seems very similar and seems trivial for migration to me. We need to check how they are used in ResolveComReference, but I think so far as we have fallback defined everything should be correct. I suggest not to migrate ResolveComReference in this PR.

@AlesProkop AlesProkop changed the title Migrate Tlblmp to Multithreaded Execution Migrate Tlblmp and AxImp to Multithreaded Execution May 15, 2026
Copy link
Copy Markdown
Member

@JanProvaznik JanProvaznik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see much value in this migration without migrating the whole ResolveComReference chain.

These tasks are never created by the TaskFactory system and routed, they're explicitly instantiated during ResolveComReference

Comment thread src/Tasks/StrongNameUtils.cs Outdated
Comment thread src/Tasks/AxTlbBaseTask.cs Outdated
@AR-May
Copy link
Copy Markdown
Member

AR-May commented May 19, 2026

I don't see much value in this migration without migrating the whole ResolveComReference chain.

These tasks are never created by the TaskFactory system and routed, they're explicitly instantiated during ResolveComReference

I rather thought that this pr would be the first step toward migrating ResolveComReference as next action.

Comment thread src/Tasks/AxTlbBaseTask.cs Outdated
Comment thread src/Tasks/AxTlbBaseTask.cs Outdated
private bool DirectoryExists(string path)
{
AbsolutePath absolutePath = TaskEnvironment.GetAbsolutePathIfValid(path);
return absolutePath.Value != null && FileSystems.Default.DirectoryExists(absolutePath);
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.

probably have same issue as FileInfoExists

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.

Also, I would have expected that DirectoryExists does exactly the same as FIleExists helper, but it is different.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is not symmetric, it was like that before the migration, I can rename the function if you think it will be better for readability.

Comment thread src/Tasks.UnitTests/AxTlbBaseTask_Tests.cs
Comment thread src/Tasks/StrongNameUtils.cs Outdated
Comment thread src/Tasks/StrongNameUtils.cs Outdated
Comment thread src/Tasks/TaskEnvironmentExtensions.cs
Comment thread src/Tasks.UnitTests/AxTlbBaseTask_Tests.cs Outdated
Comment thread src/Tasks/AxTlbBaseTask.cs
Comment thread src/Tasks/AxTlbBaseTask.cs Outdated
Comment thread src/Tasks/AxTlbBaseTask.cs Outdated
Comment thread src/Tasks/AxTlbBaseTask.cs Outdated
Comment thread src/Tasks/AxTlbBaseTask.cs Outdated
Comment thread src/Tasks/StrongNameUtils.cs Outdated
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 Migrate AxImp to multithreaded execution

5 participants