Provides access to events that are raised by adding, deleting, or changing project references. Use this object for functionality and refer to ReferencesEventsClass for this object’s documentation.
Assembly: VSLangProj (in VSLangProj.dll)
The ReferencesEvents object may be accessed from either the VSProject object or the DTE object. Each project, through the VSProject object, has a ReferencesEvents object providing access to the events of that project. The ReferencesEvents object of the DTE object may be used to connect to events of individual projects or to events of all Visual Basic projects in the solution.
The following two examples use the late-bound VBReferencesEvents property to connect to Visual Basic project events. Use CSharpReferencesEvents to connect to Visual C# events.
There are two late-bound methods for handling events. The first method allows you to connect to events for a particular project and requires the Option Strict Off statement to compile. This method returns an error if the parameter to the VBReferencesEvents call is not of type Project. The parameter to VBImportsEvents is optional. If it is omitted, events for all the Visual Basic projects in the solution are received.
' Macro editor Imports VSLangProj Option Strict Off Dim WithEvents refEvents As ReferencesEvents Sub ConnectProjectRefEvents() ' Must have Option Strict Off Dim proj As Project = DTE.Solution.Projects.Item(1) refEvents = DTE.Events.VBReferencesEvents(proj) End Sub Public Sub refEvents_ReferenceAdded(ByVal pReference _ As VSLangProj.Reference) Handles refEvents.ReferenceAdded MsgBox(pReference.Name) End Sub
The second late-bound method allows you to add event-handling methods for events in all the projects in the solution. This method does not offer a way to filter events for only a particular project. It will compile with Option Strict On.
' Macro editor Imports VSLangProj Dim WithEvents refEvents As ReferencesEvents Sub ConnectAllRefEvents() refEvents = CType(DTE.Events.GetObject("VBReferencesEvents"), _ ReferencesEvents) End Sub Public Sub refEvents_ReferenceAdded(ByVal pReference _ As VSLangProj.Reference) Handles refEvents.ReferenceAdded MsgBox(pReference.Name) End Sub