Skip to content

Add HostServices support in Out-of-Process Task Host - #12753

Merged
YuliiaKovalova merged 31 commits into
mainfrom
dev/ykovalova/host_object_support
Jan 9, 2026
Merged

YuliiaKovalova merged 31 commits into
mainfrom
dev/ykovalova/host_object_support

Conversation

@YuliiaKovalova

@YuliiaKovalova YuliiaKovalova commented Nov 12, 2025 •

Copy link
Copy Markdown
Member

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, targetName and project file path
    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

{931109D5-7DF3-494B-BABB-C6123C778239}

After

{C4F482AC-D77A-4F06-8291-122990B0D488} {3FA2F583-8097-4D20-A8BE-0F7C41BA4AC1}
@YuliiaKovalova YuliiaKovalova self-assigned this Nov 12, 2025
@YuliiaKovalova YuliiaKovalova changed the title Add host object support Nov 27, 2025
@YuliiaKovalova
YuliiaKovalova marked this pull request as ready for review November 27, 2025 17:44
Copilot AI review requested due to automatic review settings November 27, 2025 17:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 HostServices and targetName fields to TaskHostConfiguration with conditional serialization
  • Propagated HostServices and targetName through 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
Comment thread src/Shared/CommunicationsUtilities.cs Outdated
Comment thread src/Build/Instance/HostServices.cs
Comment thread src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs Outdated
Comment thread src/Build/Instance/TaskFactories/TaskHostTask.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants