MSBuild ITaskItem RecursiveDir metadata disappears

六月ゝ 毕业季﹏ 提交于 2019-11-30 15:50:25

问题


I have a custom MSBuild task, which processes a set of files and returns a modified subset of this. Basically, I just create a new ITaskItem array out of the input, skipping some items.

However, the RecursiveDir metadata disappears when this result set is returned to MSBuild! It is still with the correct values at the end of my custom task's Execute() method but when I then try to use RecursiveDir in MSBuild, I find that it is empty! This is, of course, quite a problem!

What should I do? Is this normal? The other metadata such as Filename and Extension is still there. Identity also points to the correct file. I don't modify the metadata in any way in my custom task.

I have seen other MSBuild task libraries also return ITaskItem arrays without any special processing. Yet nobody has run into this issue? Bizarre!

I am using MSBuild 3.5.


回答1:


Yes, this is normal. There is nothing you can do about it. I have gone through the MSBuild source code thorougly and apparently, the items going into a custom task and the items coming back out are completely different things. MSBuild creates its own very special items at first and later they become significantly "dumber".

The solution I found for such cases:

  1. Create an all-inclusive ItemGroup.
  2. Create a custom task that generates an ItemGroup with the files you want to remove.
  3. Use <ItemGroup Remove="@(ListFromCustomTask)" />



回答2:


I just ran into this same exact issue. I was able to successfully work around this "limitation" (MSBuild bug in my opinion) by explicitly setting the "RecursiveDir" metadata value to its current value.

After doing this, my output ITaskItem[] retained the value.



来源:https://stackoverflow.com/questions/2070569/msbuild-itaskitem-recursivedir-metadata-disappears

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!