不使用 DTE 访问构建事件
Access build events without using DTE
捕获构建事件时,您可以简单地监听 DTE2.Events.BuildEvents
事件。然而,是否可以在不使用 DTE
的情况下收听这些事件。我已经阅读并从一些人和消息来源那里听说,如果可能的话,你通常应该避免使用 DTE
,因为它的实施不佳或其他原因。
一般来说,如果您尝试自动化 Visual Studio,您可以使用标准自动化方法 DTE,或使用本机接口。本机接口以 'IVs...' 开头,例如IVs解决方案。在这两种情况下,技术都是古老的,而且记录很少。正如您所建议的,本机解决方案往往会更好。
话虽如此,对于我需要的构建任务 运行,我最终使用了 DTE,它更容易编程并且可以可靠地工作。
我发现 mztools.com 网站上同样古老的文章(不是工具!)在这方面非常有用,当然还有 MSDN 文档。将 'mztools' 添加到您的 Google 搜索中。例如,mztools says on build events (Google 'mztools build events') 是有用的,即使它的日期是 2013 年。
我只是想分享实际工作并实现我所需要的代码。这是通过 @Rich N 的帮助实现的,感谢他。其实比我想象的要简单,都是一样的程序
- 从
GetService
方法中获取Svs...
class并转换为相应的接口。
- 然后使用
Advise...
方法附加事件处理程序 Class。
// First of get the IVsSolutionBuildManager via the SVsSolutionBuildManager with the GetService method
var service = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;
// Appending the Events
service.AdviseUpdateSolutionEvents(new Events(), out var cookie)
// The class which handles the Event callbacks
public class Events : IVsUpdateSolutionEvents
{
// The implemented methods from the interface
}
捕获构建事件时,您可以简单地监听 DTE2.Events.BuildEvents
事件。然而,是否可以在不使用 DTE
的情况下收听这些事件。我已经阅读并从一些人和消息来源那里听说,如果可能的话,你通常应该避免使用 DTE
,因为它的实施不佳或其他原因。
一般来说,如果您尝试自动化 Visual Studio,您可以使用标准自动化方法 DTE,或使用本机接口。本机接口以 'IVs...' 开头,例如IVs解决方案。在这两种情况下,技术都是古老的,而且记录很少。正如您所建议的,本机解决方案往往会更好。
话虽如此,对于我需要的构建任务 运行,我最终使用了 DTE,它更容易编程并且可以可靠地工作。
我发现 mztools.com 网站上同样古老的文章(不是工具!)在这方面非常有用,当然还有 MSDN 文档。将 'mztools' 添加到您的 Google 搜索中。例如,mztools says on build events (Google 'mztools build events') 是有用的,即使它的日期是 2013 年。
我只是想分享实际工作并实现我所需要的代码。这是通过 @Rich N 的帮助实现的,感谢他。其实比我想象的要简单,都是一样的程序
- 从
GetService
方法中获取Svs...
class并转换为相应的接口。 - 然后使用
Advise...
方法附加事件处理程序 Class。
// First of get the IVsSolutionBuildManager via the SVsSolutionBuildManager with the GetService method
var service = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;
// Appending the Events
service.AdviseUpdateSolutionEvents(new Events(), out var cookie)
// The class which handles the Event callbacks
public class Events : IVsUpdateSolutionEvents
{
// The implemented methods from the interface
}