问题描述
我的外接程序如何检测何时加载解决方案?我知道DTE模型中的某处肯定有一些事件,但是我找不到它.我的加载项在Visual Studio加载时加载,但这取决于打开的解决方案.在MS失去对COM的恶意修复之前,我不想使其成为解决方案外接程序,因为解决方案外接程序必须是COM组件.
How can my add-in detect when a solution is loaded? I know there must be some event somewhere in the DTE model, but I can't find it. My add-in loads when Visual Studio loads, but it depends on a solution being open. I don't want to make it a solution add-in until MS loses their sick fixation on COM, as solution add-ins have to be COM components.
推荐答案
以下是使用C#注册事件处理的方法:
Here's how to register for event handling using C#:
_solutionEvents = _applicationObject.Events.SolutionEvents;
_solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionOpened);
_solutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(SolutionClosed);
还请注意,当用户通过双击解决方案文件打开Visual Studio时,您将不会获得打开解决方案的事件.您应该检查OnStartupComplete方法中的_applicationObject.Solution是否不为null,以正确处理这种情况.
Also note that when user opens Visual Studio by double clicking on a solution file, you won't get an event for solution opening. You should check whether _applicationObject.Solution is not null in OnStartupComplete method to handle this situation correctly.
这篇关于外接程序如何检测何时加载解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!