Skip to content

Change IDictionary<string, string> to TaskHostParameters#12620

Merged
YuliiaKovalova merged 15 commits intomainfrom
dev/ykovalova/infer_task_host_and_arch
Nov 4, 2025
Merged

Change IDictionary<string, string> to TaskHostParameters#12620
YuliiaKovalova merged 15 commits intomainfrom
dev/ykovalova/infer_task_host_and_arch

Conversation

@YuliiaKovalova
Copy link
Member

@YuliiaKovalova YuliiaKovalova commented Oct 8, 2025

Fixes #12287 , #12686 and #12683

Context

The previous implementation used IDictionary<string, string> to pass task identity parameters throughout the system. This approach had several drawbacks:

  1. Lack of Type Safety: Dictionary keys were string literals, prone to typos and requiring runtime validation
  2. Poor Discoverability: Developers had to search through code or documentation to understand what parameters were available
  3. Runtime Errors: Invalid parameter names or values were only caught at runtime
  4. Performance Overhead: Dictionary allocations and lookups added unnecessary overhead for a fixed set of parameters
  5. Unclear Intent: Dictionary usage didn't clearly communicate the specific parameters being used

What Changed

New TaskHostParameters readonly struct was added.

Main Changes:

  1. src/Framework/TaskHostParameters.cs - New struct definition
  2. src/Framework/ITaskFactory2.cs - Updated interface
  3. src/Build/Instance/TaskRegistry.cs - Identity comparison logic changes
  4. src/Framework/BinaryTranslator.cs - Serialization support

Testing

The functionality is well covered by existing task factory tests

@YuliiaKovalova YuliiaKovalova marked this pull request as ready for review October 8, 2025 14:32
@YuliiaKovalova YuliiaKovalova self-assigned this Oct 8, 2025
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 replaces the use of IDictionary<string, string> with a new TaskHostParameters readonly struct for passing task identity parameters throughout the MSBuild system. The change improves type safety by eliminating string-based dictionary keys that were prone to typos and runtime validation errors, while also providing better performance through reduced allocations and clearer API design.

Key changes:

  • Introduces the new TaskHostParameters struct with strongly-typed properties
  • Updates ITaskFactory2 interface with new overloads using TaskHostParameters
  • Refactors internal task registry and execution logic to use the new type

Reviewed Changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Framework/TaskHostParameters.cs New readonly struct defining task host parameters with runtime, architecture, and .NET host paths
src/Framework/ITaskFactory2.cs Adds new overloads using TaskHostParameters and marks old dictionary-based methods as obsolete
src/Framework/BinaryTranslator.cs Implements serialization support for TaskHostParameters
src/Build/Instance/TaskRegistry.cs Updates task registration and identity comparison logic to use TaskHostParameters
src/Shared/CommunicationsUtilities.cs Refactors handshake options generation to work with TaskHostParameters
src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs Major refactoring to use TaskHostParameters throughout task instantiation logic
Comments suppressed due to low confidence (1)

src/Build/Instance/TaskRegistry.cs:539

  • Missing closing brace for the VerifyThrowIdentityParametersValid method. The method structure appears incomplete.
            }

Refactor task factory parameter merging to check for task host factory conditionally.
@YuliiaKovalova YuliiaKovalova requested a review from a team as a code owner October 8, 2025 17:24
@surayya-MS surayya-MS self-requested a review October 13, 2025 14:30
Copy link
Member

@surayya-MS surayya-MS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@YuliiaKovalova YuliiaKovalova force-pushed the dev/ykovalova/infer_task_host_and_arch branch from cbb2a71 to 2dae9bd Compare October 27, 2025 20:06
@YuliiaKovalova YuliiaKovalova merged commit 25f6112 into main Nov 4, 2025
10 checks passed
@YuliiaKovalova YuliiaKovalova deleted the dev/ykovalova/infer_task_host_and_arch branch November 4, 2025 09:36
YuliiaKovalova added a commit that referenced this pull request Nov 6, 2025
YuliiaKovalova added a commit that referenced this pull request Nov 10, 2025
This change introduces a new read only struct that is used in Dictionary
for caching in TaskRegistry
#12620


Without a proper equality check it spawns a new process due to mismatch.

Experimental insertion without extra allocation reported:
https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/686770
YuliiaKovalova pushed a commit that referenced this pull request Nov 25, 2025
### Context
Sidecar taskhost was accidentally disabled in #12620

### Changes Made
Re-enabled sidecar taskhost functionality.

### Testing
Only unit tests.
ViktorHofer added a commit that referenced this pull request Jan 14, 2026
If the task host factory is explicitly requested, do not act as a long lived task host.
This is important as customers use task host factories for short lived tasks to release
potential locks after the build.

This goes back to the previous behavior.
This regressed with #12620
ViktorHofer added a commit that referenced this pull request Jan 14, 2026
If the task host factory is explicitly requested, do not act as a long lived task host.
This is important as customers use task host factories for short lived tasks to release
potential locks after the build.

This goes back to the previous behavior.
This regressed with #12620
ViktorHofer added a commit that referenced this pull request Jan 14, 2026
If the task host factory is explicitly requested, do not act as a long lived task host.
This is important as customers use task host factories for short lived tasks to release
potential locks after the build.

This goes back to the previous behavior.
This regressed with #12620
ViktorHofer added a commit that referenced this pull request Jan 20, 2026
If the task host factory is explicitly requested, do not act as a long
lived task host. This is important as customers use task host factories
for short lived tasks to release potential locks after the build.

This goes back to the previous behavior.
This partially regressed with
#12620

Fixes #13013
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.

Create readonly struct instead of an allocated dictionary for Dictionary<string, string> taskHostParameters

5 participants