I have a custom Build task that returns ITaskTem[] as output to my build script. I cannot find an documentation/examples on how I can access these values from with in my MSBuild script.
My Execute method calls this private method which returns the array. I would like to be able to iterate through the Output and get both the TaskItem ItemSpec and the "Message" metadata item. How can I do this?
[Output]
public ITaskItem[] FailedTestsResults { get; set; }
...
private ITaskItem[] GetFailedTests(TestResultsSummary testResultsSummary)
{
IList<TestResult> testList = testResultsSummary.Tests.ToList();
IEnumerable<TestResult> failedTests = testList.Where(x => !x.Passed);
IList<ITaskItem> failedTestsTaskItems = new List<ITaskItem>();
foreach (var failedTest in failedTests)
{
//test encountered enexpected error.
ITaskItem failTestItem = new TaskItem(failedTest.TestName);
failTestItem.SetMetadata("Message", failedTest.Message);
failedTestsTaskItems.Add(failTestItem);
}
return (ITaskItem[]) failedTestsTaskItems.ToArray();
}
I figured it out. Metadata can be accessed like so..
<Message Text="Failed: %(FailedTests.Identity) => %(FailedTests.Message)" />
Notice the use of '%' rather than '$'.