Skip to content

Harden typed task parameter infrastructure - #14819

Merged
OvesN merged 1 commit into
dotnet:mainfrom
OvesN:dev/veronikao/typed-parameter-infrastructure-fixes-upstream
Aug 26, 2026
Merged

Harden typed task parameter infrastructure#14819
OvesN merged 1 commit into
dotnet:mainfrom
OvesN:dev/veronikao/typed-parameter-infrastructure-fixes-upstream

Conversation

@OvesN

@OvesN OvesN commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Context

These issues were found while migrating real in-box tasks to typed parameters. Direct task tests passed, but real MSBuild binding, malformed inputs, logging, event forwarding, and binlog replay exposed infrastructure gaps.

Changes Made

  • Malformed typed-item paths could escape as unhandled exceptions.
    TaskItem<T> derives path values from FullPath; malformed values could throw InvalidOperationException, bypassing normal parameter-binding error handling. The constructor now converts this to ArgumentException, allowing MSBuild to report MSB4030.

    Real-world reproduction:

    <GetFileHash Files="bad%00path" />

    Before the fix, binding ITaskItem<AbsolutePath>[] could terminate the node with an unhandled exception while evaluating FullPath. After the fix, the project receives:

    MSB4030: "bad path" is an invalid value for the "Files" parameter of the "GetFileHash" task.
    
  • Logging of AbsolutePath task parameters could crash or inflate paths.
    ItemGroupLoggingHelper treated AbsolutePath as an arbitrary value type and called Convert.ChangeType, which throws because AbsolutePath is not IConvertible. Now we log absolute path correctly, using originally passed path in logs AbsolutePath.OriginalValue.

    Real-world reproduction:

    <VerifyFileHash File="input.txt"
                    Hash="3306EA2566F10A3C4071D8BADFB92A83D4F1D428555B4936D21C10F4F775B351" />

    With task-input logging enabled, MSBuild attempted to format the bound AbsolutePath and failed with:

    InvalidCastException: Object must implement IConvertible.
    MSB4166: Child node exited prematurely.
    

    The fixed output remains relative:

    Task Parameter:File=input.txt
    
  • Forwarded task-parameter events lost relative path values.
    TaskParameterEventArgs serialized AbsolutePath through ToString(), replacing a value such as input.txt with its absolute form. Forwarding now serializes OriginalValue.

    Real-world example:

    Originating node: Task Parameter:File=input.txt
    Receiving node:   Task Parameter:File=C:\repo\input.txt
    

    A distributed logger could therefore observe a different value depending on which node produced the event. Forwarded events now retain input.txt.

  • Binlog task-parameter serialization lost relative path values.
    BuildEventArgsWriter had the same ToString() behavior, so replayed binlogs differed from live output. Binlog serialization now preserves OriginalValue.

    Real-world example:

    Live build:      Task Parameter:File=input.txt
    Replayed binlog: Task Parameter:File=C:\repo\input.txt
    

    The live and replayed event streams now contain the same relative value.

Testing

Each fix has a dedicated regression test:

  • FromITaskItem_InvalidPath_ThrowsArgumentException
  • AbsolutePathTaskParameterTextUsesOriginalValue
  • TaskParameterEventForwardingPreservesAbsolutePathOriginalValue
  • BinaryLogSerializationPreservesAbsolutePathOriginalValue
  • BinaryLogSerializationWritesEmptyItemSpecForDefaultAbsolutePath

All dedicated tests pass on net11.0 and net472. The full Debug build also succeeds.

Notes

This PR contains only typed-parameter infrastructure fixes. The task migrations and user documentation are in the stacked PR OvesN/msbuild#6.

Copilot AI lite review requested due to automatic review settings August 25, 2026 08:18
@OvesN
OvesN deployed to copilot-pat-pool August 25, 2026 08:18 — with GitHub Actions Active
@OvesN
OvesN deployed to copilot-pat-pool August 25, 2026 08:18 — with GitHub Actions Active

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 hardens MSBuild’s typed task parameter infrastructure by ensuring malformed or relative AbsolutePath values don’t crash logging/forwarding/binlog replay and that invalid typed-item paths flow through normal parameter-binding error handling.

Changes:

  • Wrap FullPath metadata failures when constructing TaskItem<T> so malformed paths surface as ArgumentException (enabling MSB4030-style binding errors instead of unhandled exceptions).
  • Preserve AbsolutePath.OriginalValue (relative input) when logging task parameters, forwarding TaskParameterEventArgs, and serializing task-parameter items into binlogs.
  • Add regression tests covering invalid path binding, task-parameter text formatting, event forwarding, and binlog round-tripping.

Reviewed changes

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

Show a summary per file
File Description
src/Utilities.UnitTests/TaskItem_Tests.cs Adds regression test ensuring invalid path metadata results in ArgumentException.
src/Framework/TaskParameterEventArgs.cs Preserves AbsolutePath.OriginalValue during task-parameter event serialization.
src/Framework/TaskItem_T.cs Converts FullPath metadata failures into ArgumentException to integrate with binding error handling.
src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs Preserves AbsolutePath.OriginalValue when writing task-parameter item lists to binlog.
src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs Logs AbsolutePath parameters using OriginalValue (keeps relative input in logs).
src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs Adds regression tests for logging text, event forwarding, and binlog serialization preserving relative values.

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

Comment thread src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs
Comment thread src/Framework/TaskItem_T.cs Outdated
@OvesN
OvesN requested a review from baronfel August 25, 2026 08:36
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@OvesN
OvesN force-pushed the dev/veronikao/typed-parameter-infrastructure-fixes-upstream branch from 4244329 to c04ef83 Compare August 25, 2026 08:46

@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.

LGTM overall - but I think we need to figure out a better pattern for the type extensibility.

@OvesN
OvesN merged commit 67e01fd into dotnet:main Aug 26, 2026
10 checks passed
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.

3 participants