Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Last active December 28, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayBazuzi/7523672 to your computer and use it in GitHub Desktop.
Save JayBazuzi/7523672 to your computer and use it in GitHub Desktop.
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