如何告诉VS包我想订阅IDTExtensibility2

时间:2015-04-24 09:17:01

标签: .net vb.net visual-studio-2013 add-in visual-studio-extensions

我正在尝试创建一个VS2013扩展,以便我可以收到构建事件的通知。

我创建了一个VS包,我有一个示例Connect类实现IDTExtensibility2,并且在OnBuildProjConfigBegin事件中有我需要的代码。

如何告诉包使用该类?

我的Connect类如下供参考,但我认为我需要在其他地方更改一些内容才能使其工作:

Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE
Imports EnvDTE80
Imports System.IO
Imports System.Collections.Generic
Imports System.Windows.Forms

Public Class Connect

    Implements IDTExtensibility2


    Private _applicationObject As DTE2
    Private _addInInstance As AddIn
    Private _buildEvents As BuildEvents

    '''<summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary>
    Public Sub New()
        MessageBox.Show("New")
    End Sub

    '''<summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
    '''<param name='application'>Root object of the host application.</param>
    '''<param name='connectMode'>Describes how the Add-in is being loaded.</param>
    '''<param name='addInInst'>Object representing this Add-in.</param>
    '''<remarks></remarks>
    Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection
        MessageBox.Show("Connection")
        _applicationObject = CType(application, DTE2)
        _addInInstance = CType(addInInst, AddIn)
        _buildEvents = _applicationObject.Events.BuildEvents
        AddHandler _buildEvents.OnBuildBegin, AddressOf OnBuildBegin
        AddHandler _buildEvents.OnBuildProjConfigBegin, AddressOf OnBuildProjConfigBegin
    End Sub

    Private Sub OnBuildProjConfigBegin(ByVal project As String, ByVal projectConfig As String, ByVal platform As String, ByVal solutionConfig As String)
        MessageBox.Show("Build has begun")
    End Sub

    '''<summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary>
    '''<param name='disconnectMode'>Describes how the Add-in is being unloaded.</param>
    '''<param name='custom'>Array of parameters that are host application specific.</param>
    '''<remarks></remarks>
    Public Sub OnDisconnection(ByVal disconnectMode As ext_DisconnectMode, ByRef custom As Array) Implements IDTExtensibility2.OnDisconnection
        RemoveHandler _buildEvents.OnBuildBegin, AddressOf OnBuildBegin
        RemoveHandler _buildEvents.OnBuildProjConfigBegin, AddressOf OnBuildProjConfigBegin
    End Sub

    '''<summary>Implements the OnAddInsUpdate method of the IDTExtensibility2 interface. Receives notification that the collection of Add-ins has changed.</summary>
    '''<param name='custom'>Array of parameters that are host application specific.</param>
    '''<remarks></remarks>
    Public Sub OnAddInsUpdate(ByRef custom As Array) Implements IDTExtensibility2.OnAddInsUpdate
    End Sub

    '''<summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary>
    '''<param name='custom'>Array of parameters that are host application specific.</param>
    '''<remarks></remarks>
    Public Sub OnStartupComplete(ByRef custom As Array) Implements IDTExtensibility2.OnStartupComplete
    End Sub

    '''<summary>Implements the OnBeginShutdown method of the IDTExtensibility2 interface. Receives notification that the host application is being unloaded.</summary>
    '''<param name='custom'>Array of parameters that are host application specific.</param>
    '''<remarks></remarks>
    Public Sub OnBeginShutdown(ByRef custom As Array) Implements IDTExtensibility2.OnBeginShutdown
    End Sub

End Class

1 个答案:

答案 0 :(得分:0)

软件包不应该也不需要实现IDTExtensibility2。有几种解决方案: