我正在为visual studio 2015编写一个VSIX扩展,订阅构建事件并以异步方式执行其他验证,如下所示:
class BuildEventController
{
private readonly IThreadHandling _threading;
private readonly BuildEvents _events;
private readonly EnvDTE.DTE2 _dte2;
public BuildEventController(...)
{
_dte2 = ... ;
_threading = ... // instance of IThreadHandling
_events = _dte2.Events.BuildEvents;
}
public override void Initialize()
{
_events.OnBuildProjConfigBegin += OnBuildProjectStarted;
}
private void OnBuildProjectStarted(...)
{
_threading.AsyncPump.RunAsync(async delegate
{
await TaskScheduler.Default;
// do long-running work async
// then... cancel the build if errors
await _threading.AsyncPump.SwitchToMainThreadAsync();
CancelBuild();
});
}
private void CancelBuild()
{
_dte2.ExecuteCommand("Build.Cancel");
}
}
问题是实际构建(编译)可能在我的任务开始之前完成,我最终将失去取消构建的能力(即使我仍然可以在错误选项卡中添加错误)。
有没有办法安排我的工作在实际编译之前或之后执行,以便它作为构建过程中的附加步骤执行?