我正在尝试创建一个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
答案 0 :(得分:0)
软件包不应该也不需要实现IDTExtensibility2。有几种解决方案:
使用自动化模型(EnvDTE),按照HOWTO: Get an EnvDTE.DTE instance from a Visual Studio package中的说明获取DTE实例,然后使用DTE.Events.BuildEvents。
避免使用自动化模型并使用本机VS服务,例如IVsBuildableProjectCfg.AdviseBuildStatusCallback方法和IVsBuildStatusCallback