-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add HostServices support in Out-of-Process Task Host #12753
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
This reverts commit 2992c64.
Removed unused error handling code and associated methods.
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 enables out-of-process task hosts to access host objects registered via HostServices.RegisterHostObject(). Previously, tasks running in out-of-proc task hosts couldn't access these host objects because the necessary information wasn't transmitted to the task host process.
Key changes:
- Introduced packet version negotiation during handshake, incrementing PacketVersion from 1 to 2
- Added
HostServicesandtargetNamefields toTaskHostConfigurationwith conditional serialization - Propagated
HostServicesandtargetNamethrough the task execution call chain - Enhanced
HostServices.GetAnyMatchingMonikerNameOrITaskHost()to handle fully-qualified task names
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/TaskHostConfiguration.cs | Added HostServices and targetName fields with conditional serialization based on negotiated packet version |
| src/Shared/NodeEndpointOutOfProcBase.cs | Implemented PacketVersion exchange during handshake and updated to use NegotiatedPacketVersion |
| src/Shared/INodePacket.cs | Incremented PacketVersion to 2 and added GetNegotiatedPacketVersion helper method |
| src/Shared/CommunicationsUtilities.cs | Enhanced handshake protocol to read and negotiate packet versions between nodes |
| src/MSBuild/OutOfProcTaskHostNode.cs | Passed targetName and HostServices to task execution wrapper |
| src/MSBuild/OutOfProcTaskAppDomainWrapperBase.cs | Added logic to resolve and set host objects from HostServices |
| src/Build/Instance/TaskFactories/TaskHostTask.cs | Propagated HostServices through task initialization |
| src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs | Added HostServices parameter to CreateTaskInstance |
| src/Build/Instance/HostServices.cs | Enhanced to handle fully-qualified task names by falling back to short name lookup |
| src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs | Added HostServices support in task initialization |
| src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs | Passed HostServices from build request to task execution host |
| src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs | Updated to track and propagate negotiated packet version through NodeContext |
| src/Build.UnitTests/BackEnd/TaskHostConfiguration_Tests.cs | Updated all test cases to include new parameters (null HostServices and targetName) |
| src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs | Updated test initialization calls with null HostServices parameter |
| src/Build.UnitTests/BackEnd/AssemblyTaskFactory_Tests.cs | Updated all CreateTaskInstance calls with null HostServices parameter |
| src/MSBuild/MSBuild.csproj | Added blank line at end of file |
| src/Build/Instance/RunningObjectTable.cs | Removed BOM character from file |
| src/Framework/ITranslator.cs | Renamed PacketVersion to NegotiatedPacketVersion with updated documentation |
| src/Framework/BinaryTranslator.cs | Renamed PacketVersion to NegotiatedPacketVersion property |
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Fixes: #11510
Summary
This PR enables out-of-process task hosts to properly resolve host objects by passing HostServices and the target name through the task host communication protocol. Previously, tasks running in out-of-proc task hosts could not access host objects registered via HostServices.RegisterHostObject() because this information was not transmitted to the task host process.
Changes
Protocol Versioning & Negotiation
Introduced packet version negotiation during the handshake between parent and child nodes,
Child nodes now send their supported PacketVersion during handshake, allowing backward/forward-compatible communication between different MSBuild versions
Incremented PacketVersion from 1 to 2 to support the new fields - HostServices and targetName.
Both new fields are conditionally serialized only when NegotiatedPacketVersion >= 2.
Updated OutOfProcTaskAppDomainWrapperBase.ExecuteTask() to accept and use HostServices and targetName
Task host now calls _hostServices.GetHostObject(taskFile, targetName, taskName) to resolve the host object before task execution
Fixed HostServices.GetAnyMatchingMonikerNameOrITaskHost() to handle fully-qualified task names by falling back to short name lookup
Handshake Flow (Before vs After)
Before
After
Testing
The communication changes are well covered in scope of existing tests, how to cover HostServices support we will discuss separately.