Skip to content

Conversation

@YuliiaKovalova
Copy link
Member

@YuliiaKovalova YuliiaKovalova commented Nov 12, 2025

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

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

After

{D94C3634-0B51-4D12-B31F-F1134A45A3BD}

Testing

The communication changes are well covered in scope of existing tests, how to cover HostServices support we will discuss separately.

@YuliiaKovalova YuliiaKovalova self-assigned this Nov 12, 2025
@YuliiaKovalova YuliiaKovalova changed the title Add host object support Add HostServices support in Out-of-Process Task Host 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 finished reviewing on behalf of YuliiaKovalova November 27, 2025 17:46
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 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

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.

Add HostObject support for net task host

2 participants