Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Unit test for running a custom MSBuild task.
public void RequiredInputGetsLogged()
var buildTarget = CreateBuildTarget();
buildTarget.AddTask<TaskWithRequiredInput>().SetParameter("Foo", "hi");
const string expected = @"Inputs:
Foo = hi
AssertTargettOutput(expected, buildTarget);
private ProjectTargetElement CreateBuildTarget()
var buildTarget = ProjectRootElement.Create().AddTarget("Build");
return buildTarget;
private static void AssertTargettOutput(string expected, ProjectTargetElement projectTargetElement)
var highImportanceStringLogger = new HighImportanceStringLogger();
var success = new ProjectInstance(projectTargetElement.ContainingProject).Build(new[] { highImportanceStringLogger });
Assert.AreEqual(expected, highImportanceStringLogger.ToString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment