msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

[Feature Request]: Provide an Item Function to stringify an Item and its Metadata

Open baronfel opened this issue 1 year ago • 2 comments

Summary

It's currently very easy to 'dump' a Property during external end-to-end testing of MSBuild logic by writing key/value pairs to a file. There's not a good way to dump an Item and its metadata similarly, making it very hard to get in-build logs or checkpoints without resorting to finicky, hand-rolled serialization schemes. We should provide a way to dump an Item that parallels the logic used to dump Items to stdout with -getItem.

Background and Motivation

I'm trying to write tests for https://github.com/dotnet/sdk/pull/38504 using the SDK's testing framework for testing MSBuild, which relies on injecting targets that log specific properties to an external file, then read them in. It's very hard to do the same for Items.

Proposed Feature

There should be some function, let's say '[MSBuild]::DumpItem(Item)', that writes an Item in some sort of semi-structured format. Options might include, but are not limited to:

  • JSON Lines - i.e. one line of JSON, each line emitted as a separate Item (for future logging in a WriteLinesToFile Task?)
  • some kind of key/value keyed collection, like space-delimited key=value pairs?
  • ???

Alternative Designs

No response

baronfel avatar Feb 15 '24 19:02 baronfel

@baronfel thank you for the Feature Request, May I clarify the priority of the item?

f-alizada avatar Feb 20 '24 14:02 f-alizada

This is a nice-to-have. It would make debugging and logging easier, but is not blocking any critical functionality.

baronfel avatar Feb 20 '24 14:02 baronfel