【发布时间】:2015-04-24 09:17:00
【问题描述】:
我正在尝试创建一个 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
【问题讨论】:
-
您可能正在查看for this,“如何在 VSPackage 中运行我的加载项代码”部分。
标签: .net vb.net visual-studio-2013 add-in visual-studio-extensions