TaskStarted
有关任务及其参数的事件。
MSBuild.exe /logger:MyLogger.dll build.xml
在build.xml中有一系列任务,其中大多数任务都是为编译(C++或C#)解决方案而自定义编写的,可以通过以下自定义任务进行访问:
<DoCompile Desc="Building MyProject 1" Param1="$(Param1Value)" />
<DoCompile Desc="Building MyProject 2" Param1="$(Param1Value)" /> <!-- etc -->
自定义生成任务
DoCompile
定义为:
public class DoCompile : Microsoft.Build.Utilities.Task
{
[Required]
public string Description { set { _description = value; } }
// ... more code here ...
}
在构建运行时,当每个任务启动时,记录器模块接收
IEventSource.TaskStarted
活动,订阅如下:
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
}
}
taskStarted()
方法,我希望能够访问为其触发事件的任务的属性。
我只能访问记录器代码,不能更改build.xml或自定义生成任务。
有人能给我一个办法吗?