-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add runtime mismatch validation when Runtime is explicitly specified in custom task #12642
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
Add runtime mismatch validation when Runtime is explicitly specified in custom task #12642
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
Adds validation to ensure custom tasks execute out-of-process when a Runtime parameter (e.g., "Net") is explicitly specified but doesn't match the current process runtime. Previously, this required explicit TaskFactory="TaskHostFactory" in the UsingTask declaration.
Key Changes
- Modified type loading logic to check if task host parameters match the current process
- Introduced
isTaskHostParamsMatchCurrentProcparameter to control metadata load context usage - Added end-to-end test validating out-of-process execution with explicit Runtime specification
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/TypeLoader.cs | Added isTaskHostParamsMatchCurrentProc parameter throughout type loading chain to enable runtime mismatch detection |
| src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs | Initialized runtime mismatch detection by comparing task host parameters with current process |
| src/Build.UnitTests/TestAssets/ExampleNetTask/TestNetTaskWithImplicitParams/global.json | Added SDK configuration for test asset to prevent SDK path resolution issues |
| src/Build.UnitTests/TestAssets/ExampleNetTask/TestNetTaskWithImplicitParams/TestNetTaskWithImplicitParams.csproj | Created test project with Runtime="NET" to validate out-of-process execution |
| src/Build.UnitTests/NetTaskHost_E2E_Tests.cs | Added test verifying task executes out-of-process when Runtime is specified without TaskHostFactory |
| src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj | Added reference to new test asset's global.json file |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Context
Currently, in order to have Runtime="Net" executed out-of-proc, you must explicitly specify TaskFactory="TaskHostFactory" in the UsingTask element.
Changes Made
Added runtime mismatch validation when Runtime is explicitly specified to omit TaskFactory specification in UsingTask.
Regression
No
Risks
Low — validation logic only affects cases where Runtime is explicitly set.
Testing
Added a dedicated test.