Skip to content

Fix assembly resolution for .exe files and legacy .NET Framework tasks (CLR35 and CLR2)#12823

Merged
YuliiaKovalova merged 7 commits intomainfrom
dev/ykovalova/fix_assembly_load
Dec 10, 2025
Merged

Fix assembly resolution for .exe files and legacy .NET Framework tasks (CLR35 and CLR2)#12823
YuliiaKovalova merged 7 commits intomainfrom
dev/ykovalova/fix_assembly_load

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 + current tests confirm there are no regression.

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
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
@YuliiaKovalova YuliiaKovalova self-assigned this Dec 8, 2025
@YuliiaKovalova YuliiaKovalova merged commit 2960e90 into main Dec 10, 2025
10 checks passed
@YuliiaKovalova YuliiaKovalova deleted the dev/ykovalova/fix_assembly_load branch December 10, 2025 16:15
YuliiaKovalova added a commit that referenced this pull request Dec 12, 2025
rainersigwald added a commit to rainersigwald/msbuild that referenced this pull request Dec 15, 2025
rainersigwald added a commit that referenced this pull request Dec 15, 2025
It's not totally clear how, but this appears to have caused perf DDRIT
failures on insertion to VS. Reverting to investigate later.

* Revert "Make runtimeAssembliesCLR35_20 lazy (#12928)"
* Revert " Fix assembly resolution for .exe files and legacy .NET
Framework tasks (CLR35 and CLR2) (#12823)"
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.

4 participants