views:

24

answers:

1

I'm developing a custom MSBuild task by inheriting from the base Task class. My task calls the Copy task declared in Microsoft.Build.Tasks.dll setting the DestinationFolder property in the process. My custom task has a property called DestinationFolder declared as

public ITaskItem DestinationFolder { get; set; }

When calling this task from a build/project file I might pass in a parameter such as

<MyTask DestinationFolder="C:\Development\Test\%(RecursiveDir)"

the problem I have is that when this task executes, the DestinationFolder property seems to have no knowledge of the %(RecursiveDir) bit, instead just seems to be set to C:\Development\Test\Bin.

This question seems to suggest that there is no work-around for this problem. Is this definitely the case? I was wondering if it's possible to declare the property as a simple string then create a TaskItem object on the fly and if the DestinationFolder string contains the special %(RecursiveDir) instruction to then set up the TaskItem object accordingly.

A: 

The linked question deals with output parameters from a task, where this one deals with inputs. The problem here is that the you've declared DestinationFolder as an ITaskItem, but you're passing in a string.

You haven't given enough of an example for me to figure out exactly what you're trying to do, but assuming you have a file called "C:\Development\Test\Bin\SomeFile.txt", you could define an item in your project like:

<ItemGroup>
    <DestinationFolderArgument Include="C:\Development\Test\**\SomeFile.txt" />
</ItemGroup>
<MyTask DestinationFolder="@(DestinationFolderArgument)" />

Now your task will have access to all of the item's metadata, and RecursiveDir will contain "Bin\".

Rory MacLeod