Search code examples
c#msbuildmsbuild-task

How To Get Nested TaskItem Metadata Values in MSBuild File?


I have an MSBuild TaskItem that contains metadata gathered from a JSON configuration. An example of a single piece of metadata would be

%(Configuration.Object:Name)

and in the case of arrays would be

%(Configuration.Object:Name:0)
%(Configuration.Object:Name:1)
...

When attempting to get this key though, MSBuild is just giving me the exact string instead of interpreting it into the value. Seems as though it can't interpret the colon in the MSBuild file but I've confirmed that the value is present in the metadata by passing the entire TaskItem, @(Configuration), into a custom task. I've also tried to use transform syntax to no avail.

What is the syntax to retrieve these values in the MSBuild file?


Solution

  • I figured it out for all you devs from the future. The answer is Item Functions.

    @(Configuration->Metadata('Object:Name'))