MSBuild ITaskItem RecursiveDir metadata disappears

I have an MSBuild custom task that processes a collection of files and returns a modified subset of this. Basically, I just create a new ITaskItem array from the input, skipping some elements.

However, the RecursiveDir metadata disappears when this result set returns to MSBuild! It still contains the correct values โ€‹โ€‹at the end of my Execute () method, but when I try to use RecursiveDir in MSBuild, I find it empty! This is of course a problem!

What should I do? This is normal? Other metadata, such as file name and extension, still exist. Identity also indicates the correct file. I do not modify the metadata in any way in my custom task.

I have seen that other MSBuild task libraries also return ITaskItem arrays without any special handling. But no one has encountered this problem? Bizarre!

I am using MSBuild 3.5.

+4
source share
2 answers

Yes, it is normal. There is nothing you can do about it. I read the source code of MSBuild and, apparently, the elements included in the user task and the elements returned back are completely different things. First, MSBuild creates its own special items, and then it becomes significantly dumb.

The solution I found for such cases:

  • Create a universal group of elements.
  • Create a custom task that generates an ItemGroup with the files you want to delete.
  • Use <ItemGroup Remove = "@ (ListFromCustomTask)" />
+1
source

I just ran into the exact same problem. I was able to successfully circumvent this "restriction" (MSBuild error, in my opinion) by explicitly setting the "RecursiveDir" metadata value to the current value.

After that, my output of ITaskItem[] saved the value.

+1
source

All Articles