Re: Need help with intercepting the "Add reference" command
From: Carlos J. Quintero (carlosq_at_NOSPAMsogecable.com)
Date: 02/20/04
- Next message: jose_marcenaro_at_hotmail.com: "Re: Bug? - File could not be loaded into the Web Forms designer"
- Previous message: Steve McLellan: "Re: Is Pure C possible in VS.NET?"
- In reply to: leijtens: "Need help with intercepting the "Add reference" command"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 20 Feb 2004 12:10:46 +0100
It is difficult to say if you donīt post the minimal code to reproduce the
case, but I would say that:
> 1)
> I am starting the IDE, open project and click on Add reference the
> BeforeCommandExecute is NOT invoked.
This is normal since you have not clicked the menu item to capture the
events of the command
> 2)
> I am starting the IDE, clicked the menu item for registering, open project
> and click on Add reference the BeforeCommandExecute is NOT invoked.
This is not normal. Below you have the code to register command events
properly.
> 3)
> I am starting the IDE, open project, clicked the menu item for registering
> and click on Add reference the BeforeCommandExecute is invoked.
This is normal since you have clicked the menu item to capture the events of
the command
> When I am closing and reoping the project the BeforeCommandExecute
> is invoked every time.
Do you mean that the event is fired just opening and closing projects,
without adding references? This means that you are registering events for
more that one project command event.
The following code (VB.NET) shows how to trap events of a single command:
Private m_objDTE As EnvDTE.DTE
Private WithEvents m_objAddReferenceCommandEvents As CommandEvents
Public Sub OnConnection(ByVal application As Object, ByVal connectMode As
Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
Dim objCommand As Command
m_objDTE = CType(application, EnvDTE.DTE)
objCommand = m_objDTE.Commands.Item("Project.AddReference")
m_objAddReferenceCommandEvents =
m_objDTE.Events.CommandEvents(objCommand.Guid, objCommand.ID)
End Sub
Private Sub m_objAddReferenceCommandEvents_BeforeExecute(ByVal Guid As
String, ByVal ID As Integer, ByVal CustomIn As Object, ByVal CustomOut As
Object, ByRef CancelDefault As Boolean) Handles
m_objAddReferenceCommandEvents.BeforeExecute
MessageBox.Show("Added reference")
End Sub
Also, the technique that you are using (or the previous) captures
invocations to the Add Reference dialog, not actual references added. If you
want this last one, you can add a reference to the VSLangProj assembly, and
for each project of the loaded solution cast DTE.Project.Object to
VSLangProj.VSProject, get the Events.ReferencesEvents object and trap the
ReferenceAdded event.
-- Carlos J. Quintero (Visual Developer - .NET MVP)
- Next message: jose_marcenaro_at_hotmail.com: "Re: Bug? - File could not be loaded into the Web Forms designer"
- Previous message: Steve McLellan: "Re: Is Pure C possible in VS.NET?"
- In reply to: leijtens: "Need help with intercepting the "Add reference" command"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|