Most of the time was just spent iterating with MSBuild, trying to understand what it expected, and how it would respond to different inputs. I'm glad I'm encapsulating that here in this class, so the rest of my Task code doesn't have to worry about it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void LogProperty(PropertyInfo propertyInfo) | |
{ | |
string name = propertyInfo.Name; | |
var value = propertyInfo.GetValue(this); | |
if (value is ITaskItem[]) | |
{ | |
LogTaskItems(value as ITaskItem[], name); | |
} | |
else | |
{ | |
Log.LogMessage(MessageImportance.High, " {0} = {1}", name, value); | |
} | |
} | |
private void LogTaskItems(ITaskItem[] taskItems, string itemGroup) | |
{ | |
Log.LogMessage(MessageImportance.High, " {0} =", itemGroup); | |
foreach (var item in taskItems) | |
{ | |
LogTaskItem(item); | |
} | |
} | |
private void LogTaskItem(ITaskItem item) | |
{ | |
Log.LogMessage(MessageImportance.High, " {0}", item.ItemSpec); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void TaskItemsGetLogged() | |
{ | |
var buildTarget = CreateBuildTarget(); | |
var itemGroup = buildTarget.AddItemGroup(); | |
itemGroup.AddItem("Foo", "a"); | |
itemGroup.AddItem("Foo", "b"); | |
buildTarget.AddTask<TaskWithItems>().SetParameter("Foo", "@(Foo)"); | |
const string expected = @"Inputs: | |
Foo = | |
a | |
b | |
"; | |
AssertTargetOutput(expected, buildTarget); | |
} |
EDIT: After posting this, I noticed a bug. I had hard-coded the name on line 7 of LogProperty. Some TDD gurus insist that you write more than one test before removing hard-coded results. If I had done that, I would have caught that bug before committing my code. I'm tired, so I'm looking for shortcuts; if I had a pair, I bet we wouldn't have let that happen.