Read attributes of MSBuild custom tasks via events in the Logger

Posted by gt on Stack Overflow See other posts from Stack Overflow or by gt
Published on 2010-03-14T16:43:42Z Indexed on 2010/03/14 18:05 UTC
Read the original article Hit count: 269

I am trying to write a MSBuild logger module which logs information when receiving TaskStarted events about the Task and its parameters.

The build is run with the command:

MSBuild.exe /logger:MyLogger.dll build.xml

Within the build.xml is a sequence of tasks, most of which have been custom written to compile a (C++ or C#) solution, and are accessed with the following custom Task:

<DoCompile Desc="Building MyProject 1" Param1="$(Param1Value)" /> 
<DoCompile Desc="Building MyProject 2" Param1="$(Param1Value)" /> <!-- etc -->

The custom build task DoCompile is defined as:

public class DoCompile : Microsoft.Build.Utilities.Task
{
    [Required]
    public string Description { set { _description = value; } }

    // ... more code here ...
}

Whilst the build is running, as each task starts, the logger module receives IEventSource.TaskStarted events, subscribed to as follows:

public class MyLogger : Microsoft.Build.Utilities.Logger
{
    public override void Initialize(Microsoft.Build.Framework.IEventSource eventSource)
    {
        eventSource.TaskStarted += taskStarted;
    }

    private void taskStarted(object sender, Microsoft.Build.Framework.TaskStartedEventArgs e)
    {
        // write e.TaskName, attributes and e.Timestamp to log file
    }
}

The problem I have is that in the taskStarted() method above, I want to be able to access the attributes of the task for which the event was fired. I only have access to the logger code and cannot change either the build.xml or the custom build tasks.

Can anyone suggest a way I can do this?

© Stack Overflow or respective owner

Related posts about msbuild

Related posts about msbuild-task