tags:

views:

515

answers:

2

I'm trying to debug an MSBuild task, and I know there is some way to write to the MSBuild log from within a custom task but I forget how.

+3  A: 

The base Task class has a Log property you can use:

Log.LogMessage("My message");
Kent Boogaart
+1  A: 

For unit testing purposes, I wrap the logger around a helper class

public static void Log(ITask task, string message, MessageImportance importance)
{
 try
 {
  BuildMessageEventArgs args = new BuildMessageEventArgs(message, string.Empty, 
   task.ToString(), importance);
  task.BuildEngine.LogMessageEvent(args);
 }
 catch (NullReferenceException)
 {
  // Don't throw as task and BuildEngine will be null in unit test.
 }
}

Nowadays I'd probably convert that into an extension method for convenience.

Si