如何通过 DTE 监听 ProjectItem 的删除?
我的设计师依赖于其他解决方案项目的存在。如果删除其中一项,设计器就会崩溃,您必须编辑为 XML 才能修复。不太用户友好。
不过,我确实拥有代表 Visual Studio 实例的 DTE 对象以及我所依赖的 ProjectItems。
是否可以在 DTE 深处的某个地方注册一个侦听器来删除该 ProjectItem?如果是这样,我会怎么做?
I've got a designer that relies on the existence of other solution items. If one of those items is deleted the designer crashes and you have to edit as XML to fix. Not exactly user friendly.
I do, however, have the DTE object representing the instance of Visual Studio, as well as the ProjectItems I am dependent on.
Is it possible to, somewhere in the depths of the DTE, register a listener for the deletion of that ProjectItem? And, if so, How would I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来罪魁祸首是垃圾收集。我发现以下两个事件集的行为相同。
两者的关键是确保在订阅者中保留对事件对象的引用。一旦我添加了引用,它们的行为就像我预期的那样。
It looks like the culprit here is garbage collection. I found the following two event sets behaved identically.
The key to both was making sure to keep a reference to the events object in the subscriber. Once I added the reference, they behaved like I expected.
请查看这篇常见问题解答文章,其中解释了如何注册 ProjectItems 事件(包括 ItemDeleted)。
Check out this FAQ article which explains how to register for ProjectItems events (including ItemDeleted).