Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
test for logging MSBuild items items
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);
}
[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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment