0

以下是我从 MSDN ( http://msdn.microsoft.com/en-us/library/vstudio/envdte.addin.aspx ) 复制的 Addin 代码示例,并对其进行了一些修改。我通过 VS2008 创建了一个 Add-in 项目并将以下代码粘贴到其中。

但它似乎无法正常工作。

1>更新前后的DTE插件计数不变

2> 添加插件的Guid全为零

3> 我得到错误:参数不正确,在代码行:DTE.Solution.AddIns.Add

    Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    Me.AddInExample(_applicationObject)
End Sub
Function BrowseFile() As String
    Dim OpenFileDialog1 As New OpenFileDialog
    OpenFileDialog1.Filter = "*.dll file (*.dll)|*.dll|All files (*.*)|*.*"
    OpenFileDialog1.FilterIndex = 1dialog
    OpenFileDialog1.RestoreDirectory = True
    If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        'MsgBox(OpenFileDialog1.FileName)
        Return OpenFileDialog1.FileName
    End If
    Return ""
End Function
Sub AddInExample(ByVal DTE As DTE2)
    ' For this example to work correctly, there should be an add-in 
    ' available in the Visual Studio environment.
    ' Set object references.
    Dim addincoll As AddIns
    Dim addinobj As AddIn
    ' Register an add-in, check DTE Add-in count before and after the 
    ' Update.
    addincoll = DTE.AddIns
    MsgBox("AddIns collection parent name: " & addincoll.Parent.Name)
    MsgBox("Number of Add-ins: " & addincoll.Count)
    ' NOTE: Use regsvr32 for Visual C++, regasm for [Visual Basic 
    ' and Visual C#. Also, the pathname used below is an example only.
    'Shell("regasm F:\AddIns\RegExplore\Debug\regexplore.dll")
    'Shell("C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm e:\AddinTest1.dll")
    Shell("C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm " & BrowseFile())
    addincoll.Update()
    MsgBox("Number of Add-ins: " & addincoll.Count)
    addinobj = addincoll.Item(1)
    ' Connect the add-in if it is not already connected
    ' and list its SatelliteDLLPath and Guid.
    If addinobj.Connected = False Then
        addinobj.Connected = True
    End If
    MsgBox("Satellite DLL Path: " & addinobj.SatelliteDllPath)
    MsgBox("DLL GUID: " & addinobj.Guid)
    ' Activates a solution add-in so that it is available, then 
    'deactivates it.
    MsgBox(addinobj.ProgID)
    MsgBox(addinobj.Description)
    MsgBox(addinobj.Name)
    addinobj = DTE.Solution.AddIns.Add(addinobj.ProgID, addinobj.Description, addinobj.Name, False)
    DTE.Solution.AddIns.Item(1).Remove()
End Sub
4

1 回答 1

0

如果我是你,我会从头开始:MSDN VS Addin

这样做可以让您调试(单步执行)您的代码,并为您提供一个良好的开端。您所在的页面假定您已经知道如何执行此操作。

于 2013-09-20T14:18:38.750 回答