-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix assembly resolution for .exe files and legacy .NET Framework tasks (CLR35 and CLR2) #12823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.csto 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 |
Co-authored-by: Copilot <[email protected]>
10e8cf5 to
89fdbf1
Compare
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.
msbuild/src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs
Line 335 in ee6457a
look at
!TaskHostParametersMatchCurrentProcessChanges Made
Fixed assembly enumeration: Previously only
.dllfiles were added to MetadataLoadContext's resolver. Now.exefiles 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.