Reputation: 18983
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.
Upvotes: 5
Views: 3326
Reputation: 16858
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.
Upvotes: 1
Reputation: 178810
The base Task class has a Log
property you can use:
Log.LogMessage("My message");
Upvotes: 9