未在数据库项目中触发ProjectItemsEvents [英] ProjectItemsEvents not firing in Database Project

查看:83
本文介绍了未在数据库项目中触发ProjectItemsEvents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 扩展名类型:加载项
  2. VS版本:
  1. Extension Type:  Add-In
  2. VS Version:  

Microsoft Visual Studio 2008
版本9.0.30729.1 SP
Microsoft .NET Framework
版本3.5 SP1

Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
Microsoft .NET Framework
Version 3.5 SP1

安装版:专业

Microsoft Visual Basic 2008 91605-270-0045093-60201
Microsoft Visual C#2008 91605-270-0045093-60201
用于办公室的Microsoft Visual Studio 2008工具91605-270-0045093-60201
Microsoft Visual Web Developer 2008 91605-270-0045093-60201


3. Windows版本: XP专业版(v 5.1 Build 2600,SP2)
4.错误消息:没有错误消息出现.相反,我期望从解决方案资源管理器树中删除对象时触发ItemRemoved事件,但不会触发.
5. .NET语言: C#.
6.问题代码:

在OnConnection方法中:
ProjectItemsEvents _ globalProjectItemsEvents;
_applicationObject =( DTE2 )应用程序;

Microsoft Visual Basic 2008   91605-270-0045093-60201
Microsoft Visual C# 2008   91605-270-0045093-60201
Microsoft Visual Studio 2008 Tools for Office   91605-270-0045093-60201
Microsoft Visual Web Developer 2008   91605-270-0045093-60201


3. Windows Version:  XP Professional (v 5.1 Build 2600, SP2)
4. Error Message:  No error message appears.  Instead, I'm expecting the ItemRemoved event to fire when I delete an object from the Solution Explorer tree, but it's not firing.
5. .NET Language:  C#.
6. Problem Code:  

In the OnConnection method:
ProjectItemsEvents _globalProjectItemsEvents;
_applicationObject = (DTE2)application;

EnvDTE. 事件 事件= _applicationObject.Events;
_globalProjectItemsEvents =((EnvDTE80. Events2 )events).ProjectItemsEvents;
_globalProjectItemsEvents.ItemRemoved + = _dispProjectItemsEvents_ItemRemovedEventHandler (GlobalProjectItemsEvents_ItemRemoved);
_globalProjectItemsEvents .ItemRenamed + =
new _dispProjectItemsEvents_ItemRenamedEventHandler (GlobalProjectItemsEvents_ItemRenamed );

EnvDTE.Events events = _applicationObject.Events;
_globalProjectItemsEvents = ((EnvDTE80.Events2)events).ProjectItemsEvents;
_globalProjectItemsEvents.ItemRemoved +=
new _dispProjectItemsEvents_ItemRemovedEventHandler(GlobalProjectItemsEvents_ItemRemoved);
_globalProjectItemsEvents.ItemRenamed +=
new _dispProjectItemsEvents_ItemRenamedEventHandler(GlobalProjectItemsEvents_ItemRenamed);

在OnDisconnection方法中:

In the OnDisconnection method:

如果 (_globalProjectItemsEvents!= null )
{
_globalProjectItemsEvents.ItemRemoved + =
_dispProjectItemsEvents_ItemRemovedEventHandler (GlobalProjectItemsEvents_ItemRemoved);
_globalProjectItemsEvents.ItemRenamed + =
new _dispProjectItemsEvents_ItemRenamedEventHandler (GlobalProjectItemsEvents_ItemRenamed);
}

if (_globalProjectItemsEvents != null)
{
_globalProjectItemsEvents.ItemRemoved +=
new _dispProjectItemsEvents_ItemRemovedEventHandler(GlobalProjectItemsEvents_ItemRemoved);
_globalProjectItemsEvents.ItemRenamed +=
new _dispProjectItemsEvents_ItemRenamedEventHandler(GlobalProjectItemsEvents_ItemRenamed);
}


最后,在Connect.cs的底部:


And finally, at the bottom of Connect.cs:

公共 void GlobalProjectItemsEvents_ItemRemoved(EnvDTE . ProjectItem projectItem)
{
MessageBox .Show( "请不要忘记删除此文件(" > + projectItem.Name + ).当前版本的VSAdd-In无法处理. );
}

public void GlobalProjectItemsEvents_ItemRemoved(EnvDTE.ProjectItem projectItem)
{
    MessageBox.Show("Please don't forget to delete this file (" + projectItem.Name + ") in SPResync as well. Current version of the VSAdd-In does not handle this.");
}

公共 void GlobalProjectItemsEvents_ItemRenamed(EnvDTE . ProjectItem projectItem, 字符串 OldName)
{
MessageBox .Show( "请不要忘记重命名此文件(" + projectItem.Name + ").当前版本的VSAdd-In无法处理此问题." );
}

奇怪的是,我还有其他事件(文档事件)并且它们工作正常.有什么想法吗?

7.重现问题的步骤.
将上面的代码放入Connect.cs文件中,然后运行加载项.当您尝试从解决方案资源管理器中删除文件时,应触发ItemRemoved事件,并在上方显示消息框.

8.发生错误的环境.
开发人员计算机.


感谢您的帮助,

SB

public void GlobalProjectItemsEvents_ItemRenamed(EnvDTE.ProjectItem projectItem, string OldName)
{
    MessageBox.Show("Please don't forget to rename this file (" + projectItem.Name + ") in SPResync as well. Current version of the VSAdd-In does not handle this.");
}

The strange thing is that I have other events (Document events) and they are working fine.  Any ideas?

7. Step to reproduce problem.
Put in the above code in a Connect.cs file and run Add-In.  When you try to delete a file from Solution Explorer the ItemRemoved event should fire, displaying the MessageBox above.

8. Environment where error occurs.
Developer machine.


Thanks for your help,

SB

推荐答案

首先,解决您的代码问题:

PRB:Visual Studio .NET事件与外接程序断开连接.

第二,Visual Studio的新建项目"对话框中有三种数据库项目.您正在使用哪一个?有一些项目被称为未建模项目",这意味着它们几乎不支持自动化(EnvDTE),因此大多数属性和方法均不起作用,我猜事件也是如此.数据库项目(至少是VS.NET 2002的原始类型)是这种未建模的项目.在这种情况下,您应该使用SDK中的服务来获取信息.加载项可以使用SDK中的服务,而无需SDK包.请参阅:

如何:从加载项获取Visual Studio服务

First, fix this problem of your code:

PRB: Visual Studio .NET events being disconnected from add-in.

Second, there are three kind of database projects in New Project dialog of Visual Studio. Which one are you using? There are some projects that are called "unmodeled projects", which means that they almost don't support automation (EnvDTE) so most properties and methods don't work and I guess events too. Database projects (at least the original kind of VS.NET 2002) are of this kind of unmodeled projects. In this case you should use services from the SDK to get the information. Add-ins can use services from the SDK, no need for a SDK package. See:

HOWTO: Get a Visual Studio service from an add-in


这篇关于未在数据库项目中触发ProjectItemsEvents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆