Skip to content

Conversation

@YuliiaKovalova
Copy link
Member

@YuliiaKovalova YuliiaKovalova commented Nov 24, 2025

Context

The recent change #12642 helped to uncover a long-term bug when a custom task was eventually executed out-of-proc, but due to lack of architecture/runtime match check BEFORE the TypeLoad, it was lazily loaded in-proc and pushed out-of-proc later.

useTaskFactory = _taskHostFactoryExplicitlyRequested || !TaskHostParametersMatchCurrentProcess(mergedParameters);

look at !TaskHostParametersMatchCurrentProcess

Changes Made

  • Fixed assembly enumeration: Previously only .dll files were added to MetadataLoadContext's resolver. Now .exe files are also included, since executables can be valid managed assemblies and dependencies.

  • Added legacy .NET Framework support (.NET Framework only): Added assembly discovery for v2.0 and v3.5 framework directories to support tasks that depend on legacy Microsoft.Build.Utilities.dll (as opposed to the modern Microsoft.Build.Utilities.Core.dll).

Test

Locally tested with custom tasks using both modern and legacy MSBuild assemblies.

Copilot AI review requested due to automatic review settings November 24, 2025 15:40
@YuliiaKovalova YuliiaKovalova changed the title Fix assembly resolution for exe files Fix assembly resolution for .exe files Nov 24, 2025
Copilot finished reviewing on behalf of YuliiaKovalova November 24, 2025 15:43
Copy link
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 fixes a long-standing bug in assembly resolution for custom tasks executed out-of-process. The issue was that executables (.exe files) were not being included when gathering assemblies for the MetadataLoadContext resolver, causing dependency resolution failures when tasks or their dependencies were packaged as executables. Additionally, the PR enhances runtime assembly discovery on .NET Framework by including assemblies from v2.0 and v3.5 framework directories.

Key Changes

  • Enhanced TypeLoader.findRuntimeAssembliesWithMicrosoftBuildFramework() to include .NET Framework v2.0 and v3.5 assemblies on .NET Framework builds
  • Fixed LoadAssemblyUsingMetadataLoadContext() to enumerate both .dll and .exe files as valid managed assemblies
  • Added FrameworkLocationHelper.cs to the MSBuild project to support framework path resolution

Reviewed changes

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

File Description
src/Shared/TypeLoader.cs Added .NET Framework v2.0/v3.5 assembly discovery and fixed assembly enumeration to include .exe files alongside .dll files
src/MSBuild/MSBuild.csproj Included FrameworkLocationHelper.cs shared file to enable framework path lookups

@YuliiaKovalova YuliiaKovalova marked this pull request as draft November 25, 2025 10:52
@YuliiaKovalova YuliiaKovalova removed the request for review from baronfel December 5, 2025 11:54
@YuliiaKovalova YuliiaKovalova force-pushed the dev/ykovalova/fix_assembly_load branch from 10e8cf5 to 89fdbf1 Compare December 5, 2025 16:33
@YuliiaKovalova YuliiaKovalova changed the title Fix assembly resolution for .exe files Fix assembly resolution for .exe files and legacy .NET Framework tasks (CLR35 and CLT2) Dec 5, 2025
@YuliiaKovalova YuliiaKovalova changed the title Fix assembly resolution for .exe files and legacy .NET Framework tasks (CLR35 and CLT2) Fix assembly resolution for .exe files and legacy .NET Framework tasks (CLR35 and CLR2) Dec 5, 2025
@YuliiaKovalova YuliiaKovalova marked this pull request as ready for review December 5, 2025 16:40
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.

2 participants