Why Doesn't Delete Take Wildcards?

Here's another question from our internal conversion discussion alias that came through last week:

Does the Delete task in MSBuild not use wildcards? The documentation doesn’t say anything about it but that seems to be the behavior I am seeing. I can always create an ItemList then pass that into delete, but I wanted to verify this was “right”.

The person asking the question is correct: the right way to do this is to create an ItemGroup that contains the list of items you want to delete. Generally you'll do this by specifying each file individually, although you can use a wildcard in the ItemGroup's Include attribute to pick up files as well. You then pass this ItemGroup into the delete task to perform the delete.

Why do we do it this way? We really wanted to ensure people passed around strongly-typed lists of objects through the build process, so things like metadata can flow through the entire build. If you have an individual task like delete take wildcards, people will tend to use the wildcards in the task directly instead of creating a strongly-typed group first.

Of course, sometimes you can't know ahead of time what the item group will be, and that's why we have the CreateItem task (which is, as we've found during the conversion of our internal build process, often required and never very pretty...).

[ Author: Neil Enns ]