Skip to content

Handle cross-runtime task parameter binding - #14913

Merged
JanProvaznik merged 15 commits into
dotnet:mainfrom
AlesProkop:alesprokop/fix-14680-schema-binding
Sep 22, 2026
Merged

JanProvaznik merged 15 commits into
dotnet:mainfrom
AlesProkop:alesprokop/fix-14680-schema-binding

Conversation

@AlesProkop

@AlesProkop AlesProkop commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #14680

Context

.NET Framework MSBuild cannot always resolve parameter types belonging to a Runtime="NET" task. This could leave null property entries or pass a null type into parameter validation. The worker now preserves the expansion shape and leaves final conversion to a compatible .NET task host.

Changes Made

  • Kept LoadedType.Properties dense and added bounded metadata-signature fallback for supported scalar and array shapes.
  • Reused worker-side expansion, escaping, and TaskEnvironment path rooting; added host-side conversion through ValueTypeParser.
  • Preserved custom reference-type ITaskItem scalar, array, and null outputs using existing TaskParameter wire tags.
  • Detected host conversion support and reported MSB4069 before sending unsupported values, while retaining empty optional parameters and legacy-compatible Int32 enum arrays.
  • Declared the System.Reflection.Metadata dependency for Microsoft.Build.Framework on .NET Framework.

Testing

  • Built the repository and the Framework/Engine test projects with MSBUILDFORCEMULTITHREADED=1: 0 warnings, 0 errors.
  • PropertySignatureClassifierIsBounded covered excessive nesting and malformed counts on net472 and net11.
  • NetTaskHost_BindsParametersUnavailableInWorkerRuntime covered enum inputs, paths and escaping, value outputs, and custom item/null outputs with metadata.
  • NetTaskHost_DoesNotSendConvertedParametersToOldHost covered old-host rejection.
  • OldNetTaskHostAllowsOptionalConversionParameterWhenExpansionIsEmpty covered empty scalar and vector inputs.
  • OldNetTaskHostRejectsRequiredEmptyConversionArray covered required-array rejection.
  • OldNetTaskHostKeepsLegacyInt32EnumArrayTransport and Int32EnumArrayUsesLegacyPrimitiveArrayTransport covered existing enum-vector compatibility.
  • Existing AbsolutePathParameter and AbsolutePathArrayParameter transport tests passed.

Result: 13 selected tests passed, 0 failed, 0 skipped.

Notes

  • Kept broader task-host runtime-identity changes, new typed-generic item input support, and enum-array output-format changes out of scope.

@AlesProkop
AlesProkop force-pushed the alesprokop/fix-14680-schema-binding branch from cd55f98 to b6e4dfd Compare September 2, 2026 11:35
Preserve unresolved parameter shapes for worker expansion and perform final conversion in a compatible .NET task host. Keep old-host behavior and custom item output metadata without changing the wire protocol.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 0308e243-44f8-4ce1-b36f-e206f0fa4cd8
@AlesProkop
AlesProkop force-pushed the alesprokop/fix-14680-schema-binding branch from f565286 to 665d2de Compare September 9, 2026 08:15
Keep required empty enum vectors compatible with older task hosts and preserve null path-array elements through existing transport. Cover metadata-only binding, unsupported array ranks, and output property semantics.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 513be76c-06ca-4701-b762-a0a230a9f596
@AlesProkop

Copy link
Copy Markdown
Member Author

Review — WHOLE PR #14913 · 17 files, +980/−28

Methodology: portable core + dotnet/msbuild expert-reviewer · Panel: GPT-5.6 Sol lead + GPT-5.6 Terra behavioral + GPT-5.5 red-team · 24/24 dimensions evaluated
Context: Reviewed 0ff3bda45be8c3dfbc049c905edb63453d65b77a…76d9f728de75e9d32a14a3f114516b40dbc74d7b; considered prior PR feedback and linked-issue discussion · 0 open inline threads
Mode: Deep
Validation: inspection only; tests not rerun for this review

Verdict: 🟡 COMMENT — address findings (non-blocking) — 0 blocking, 0 major, 3 moderate, 1 nit · 19 of 24 evaluated dimensions clean

The previously identified blocking and major issues are fixed in 76d9f728de. The four remaining observations below are optional follow-ups, not requirements for merging. I would not expand this PR to address them; these findings alone should not block it. This is review feedback, not a substitute for maintainer sign-off.

Optional, non-blocking observations (4)

🟡 MODERATE · Performance — Runtime type-resolution misses are repeated for every invocation. · TaskExecutionHost.cs:1582

  • Scenario: A task-local enum resolves through metadata, but its assembly-qualified name cannot resolve in the Framework worker. Every task invocation retries Type.GetType before using the already-known expansion shape.
  • Why it matters: Repeated cross-runtime tasks perform avoidable reflection and potentially assembly probing. Already raised by @AlesProkop. No meaningful slowdown has been demonstrated.
  • Confidence: Medium · repeated work is confirmed; its performance cost is unmeasured.
  • Possible follow-up: For capable .NET hosts, use the precomputed expansion shape directly. Retain runtime resolution where legacy compatibility requires it; avoid permanently caching misses across changing assembly-load state.

🟡 MODERATE · Error Messages — MSB4069 can report the surrogate rather than the declared parameter type. · TaskExecutionHost.cs:1607–1610

  • Scenario: An unavailable enum dependency sends MyEnum[] through raw-signature fallback, which represents its expansion shape as string[]. An older host then rejects the parameter.
  • Why it matters: The error says System.String[] is unsupported, hiding the actual declared type. This affects failure messaging, not successful binding.
  • Confidence: High · the classifier discards the declared name and the diagnostic reads the surrogate's FullName.
  • Possible follow-up: Preserve a separate declared-type display name and use it in diagnostics. Cover an unresolved enum/struct, not only paths whose surrogate names happen to match.

🟡 MODERATE · Logging & Diagnostics — Ordinary conversion failures still use fatal task-crash logging. · OutOfProcTaskAppDomainWrapperBase.cs:395–401

  • Scenario: Mode="Bogus" fails enum conversion. The host returns CrashedDuringInitialization, and the parent calls LogFatalError.
  • Why it matters: MSB4030 includes an exception stack; Debug builds additionally tell users to report an unhandled task-owner bug, although the problem is invalid project input. Successful binding and output correctness are unaffected.
  • Confidence: High · traced through TaskHostTask.HandleTaskHostTaskComplete and LoggingServiceLogMethods.
  • Possible follow-up: Route expected conversion rejection through ordinary localized error logging, retaining fatal handling for actual constructor/setter failures. Add negative host-conversion coverage.

⚪ NIT · Documentation — The transport comment still says custom value-type inputs are unsupported. · TaskParameter.cs:503

  • Possible follow-up: Explain that deserialization leaves values as strings; capable .NET task hosts reconstruct inputs, while output gathering consumes those strings.

✅ Clean (19)

✅ Backward compatibility — required empty enum vectors and existing Int32 transport remain supported.
✅ ChangeWave discipline — corrected paths restore intended behavior without new warnings or switches.
✅ String comparisons — runtime names use ordinal comparison; capability-cache paths use the platform-aware comparer.
✅ API surface — no production public API changes.
✅ Target authoring — test task declarations and outputs follow existing conventions.
✅ Design — worker-owned expansion and host-owned conversion remain separated; the full schema handshake stays deferred.
✅ Cross-platform behavior — runtime-specific code is guarded and Framework integration tests are Windows-scoped.
✅ Simplicity — production changes use focused helpers without a new general-purpose framework.
✅ Concurrency — the capability cache is concurrent and node keys remain immutable.
✅ Naming — expansion, unresolved-type, and capability members describe their roles.
✅ SDK integration — existing SDK-selection contracts remain intact; broader host identity remains an explicit non-goal.
✅ C# correctness — enum/underlying-array compatibility and runtime guards are valid.
✅ Path handling — worker-side TaskEnvironment rooting is preserved; metadata streams are disposed.
✅ Build infrastructure — the Framework dependency and shared serializer are wired into their consuming projects.
✅ Scope discipline — changes remain concerned with parameter binding, transport, and regression coverage.
✅ Evaluation model — batching, escaping, lookup, and expansion stay in the worker.
✅ Correctness — the fixed empty-vector, multidimensional, mixed-null, all-null, and empty-output cases are covered.
✅ Dependencies — reflection metadata uses the existing centrally managed version.
✅ Security — fallback decoding is bounded; the previous recursive decoder is gone.

@AlesProkop
AlesProkop marked this pull request as ready for review September 9, 2026 12:05
Copilot AI lite review requested due to automatic review settings September 9, 2026 12:05

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.

🟡 Changes recommended

The new host-conversion capability probe in SupportsTaskParameterConversion can compute an invalid probe path when MSBuildAssemblyPath is not a directory, causing false “old host” detection and incorrect MSB4069 failures.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens task parameter binding when a .NET Framework MSBuild worker evaluates Runtime="NET" tasks whose parameter types aren’t resolvable in the worker runtime. It keeps reflected parameter metadata usable (no null holes), preserves wire-shape for values/items across the task-host boundary, and defers final type conversion to the .NET task host when necessary.

Changes:

  • Makes LoadedType.Properties resilient to unresolvable parameter types and adds a bounded metadata-signature fallback to classify supported scalar/array shapes for expansion.
  • Adds host-side conversion for deferred values (via ValueTypeParser) and preserves ITaskItem-shaped outputs (including null outputs) using TaskParameter wire tags.
  • Adds capability detection for “conversion-aware” hosts and expands unit/E2E coverage for cross-runtime binding, null-preserving value-type arrays, and enum-array legacy transport.
File summaries
File Description
src/Shared/UnitTests/TaskParameter_Tests.cs Adds coverage for null-preserving ValueTypeArray transport and legacy Int32 enum-array transport.
src/Shared/TaskParameter.cs Adds CreateForTaskOutput and preserves null elements when serializing ValueTypeArray.
src/Shared/TaskHostTaskComplete.cs Avoids double-wrapping values already serialized as TaskParameter.
src/MSBuild/OutOfProcTaskAppDomainWrapperBase.cs Converts deferred parameter values on the .NET host side and preserves null task outputs via TaskParameter.
src/Framework/TaskPropertyInfo.cs Allows internal mutation of IsValueTypeOutputParameter for metadata-load scenarios.
src/Framework/ReflectableTaskPropertyInfo.cs Carries unresolved-type and expansion-type hints through reflection-backed task property info.
src/Framework/Microsoft.Build.Framework.csproj Adds System.Reflection.Metadata dependency for .NET Framework builds.
src/Framework/Loader/LoadedType.cs Keeps properties dense and classifies expansion types (including via metadata signature parsing) for unresolved types.
src/Framework.UnitTests/LoadedType_Tests.cs Adds boundedness tests for signature classification.
src/Build/Instance/TaskFactories/TaskHostTask.cs Tracks whether the NET task host supports deferred-parameter conversion; preserves TaskParameter outputs.
src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs Avoids crashes on unresolved types, defers conversion to host when needed, and improves type-name reporting in diagnostics.
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs Adds host capability probing (metadata-based) and keys task hosts by conversion capability.
src/Build.UnitTests/TestAssets/ExampleNetTask/TestNetTask/TestParameterBinding.proj Adds a test project to validate binding/escaping and output round-trips.
src/Build.UnitTests/TestAssets/ExampleNetTask/ExampleTask/ExampleTask.cs Expands the example NET task with enums, path types, and typed/custom item outputs.
src/Build.UnitTests/NetTaskHost_E2E_Tests.cs Adds end-to-end tests for cross-runtime parameter binding and old-host rejection behavior.
src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs Adds coverage for old-host behaviors and null-preserving value-type-array output semantics.
src/Build.UnitTests/BackEnd/TaskBuilderTestTask.cs Adds an enum-array parameter hook for task-host binding tests.
Review details
  • Files reviewed: 17/17 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Have a couple notes, and my brain is a little twisted, but this looks like it's going in the right direction!

@rainersigwald rainersigwald left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would really appreciate a clear summary of how all of the task parameter analysis and passing works. Can you derive a doc for that?

Comment thread src/Shared/TaskParameter.cs Resolved
@AlesProkop

Copy link
Copy Markdown
Member Author

@rainersigwald I will write here a high-level summary and send you the document.

So, the PR does this:

  1. We firstly discover the parameters by reading the task's properties and their attributes. If the worker cannot resolve a property type, a bounded signature reader extracts enough information so that it can make the expansion without knowing the specific type, this is hardcoded - scalar, array, path.

  2. Then, the worker expands the parameters.

  3. Then, the transport carries parameter names, values, and transport categories. The .NET task host loads the actual tasks, obtains the property types, and converts the received values.

  4. The host returns values with their transport categories. The worker turns these into MSBuild properties or items. Preserving the task-item category for null outputs lets this work even when the worker cannot resolve the declared output type.

Before deferring conversion, MSBuild checks whether the selected host supports it. Older hosts retain their compatible paths; values requiring unsupported conversion are rejected.

Keep raw signature inspection in the engine while preserving unresolved parameter expansion and old-host compatibility.

Co-authored-by: Copilot App <[email protected]>

@JanProvaznik JanProvaznik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would really appreciate conceptual explanation of the changes in the PR description, I think it's a bit wasteful for me to need to load the full context of the original issue and diff to an agent to get to what is this change doing.

Retain recoverable declared type identities separately from expansion surrogates so unsupported parameter diagnostics report the original type.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 43c02ab6-cf09-483b-a2dd-0293e1bc849e
rainersigwald and others added 3 commits September 18, 2026 10:31
Exercise TaskBuilderTestTask from the Core test assembly through Framework MSBuild's NET task host, asserting successful binding and preservation of item identity, full path, and metadata. This captures the desired behavior without changing the currently incomplete typed-item binding implementation.

Co-authored-by: Copilot App <[email protected]>

@rainersigwald rainersigwald left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like this doesn't support ITaskItem<FileInfo> and friends. Just pushed a test that should exercise that.

Comment thread src/Shared/TypeLoader.cs Resolved
Comment thread src/Shared/TypeLoader.cs Resolved
Gate cross-runtime parameter conversion on the task host protocol version and preserve typed task-item binding across host boundaries.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 43c02ab6-cf09-483b-a2dd-0293e1bc849e
Comment thread src/Shared/TypeLoader.cs Resolved

@rainersigwald rainersigwald left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My comments aren't blocking so removing the block.

@JanProvaznik

Copy link
Copy Markdown
Member

@rainersigwald "not blocking" as in this should be merged now at the RC2 deadline time or tomorrow after branching?

Group host acquisition options, use structured launch identities, and clarify task parameter conversion state.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 43c02ab6-cf09-483b-a2dd-0293e1bc849e
@JanProvaznik
JanProvaznik merged commit fead790 into dotnet:main Sep 22, 2026
14 checks passed
@JanProvaznik

Copy link
Copy Markdown
Member

/backport to vs18.12

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to vs18.12 (link to workflow run)

rainersigwald pushed a commit that referenced this pull request Sep 22, 2026
Backport of #14913 to vs18.12

### Summary

Prior to this change, tasks that use strongly-typed parameters would
fail when run in a `Runtime="NET"` taskhost.

### Customer Impact

Blocks the use of strongly-typed task parameters in .NET-only tasks,
which is an increasing percentage of first-party tasks and an intended
migration target.

### Regression?

No, this was a bug in the new implementation of strongly-typed task
parameters.

### Testing

Unit tests and new end-to-end scenario testing for strongly-typed
parameters in a .NET taskhost.

### Risk

Low; unblocks migration work but shouldn't affect any task that doesn't
use the new feature.

Co-authored-by: Aleš Prokop <[email protected]>
Co-authored-by: Copilot <[email protected]>
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.

Unresolvable task parameter type crashes with NullReferenceException instead of reporting a diagnostic

5 participants