none
A Addin object sample does not work

    Question

  • Following is a code sample of Addin I copied from MSDN and did some modifications to.

    But it seems that it does not work properly.

    1> DTE Add-in count before and after the  Update does not change

    2> Guid of the added addin is all zeros

    3> I get error: The parameter is incorrect, at code line: 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

    Friday, September 20, 2013 5:05 AM

Answers

  • Thanks for your feedback.

    As mentioned in the   Add-In Registration above,after an add-in is created, it is necessary to register it to .addin file with Visual Studio before it can be activated in Add-In Manager.

    If you want to install the add-in on another computer, the .addin file must be placed in a location where Visual Studio checks for add-ins. These locations are listed in the Options dialog box, in the Environment node, on the Add-in Security page.

    Please check if you have assigned the location correctly.

    If you register it manually, however, Add-In Manager would not find the path that is not in accord with the one that was automatically created by the Add-In Wizard.

    Best Regards,

    Jane.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, September 30, 2013 5:05 AM

All replies

  • I found that the example code at http://msdn.microsoft.com/en-us/library/vstudio/envdte.addin.aspx shows how

    to register a solution addin after I read article 'How to: Create Solution Add-ins'

    (http://msdn.microsoft.com/en-us/library/ms165621(v=vs.90).aspx). Then I following that article to create a

    solution addin:

    1> Create an addin project and accept all default settings.

    2> Right click the addin project, select Properties, check Register for COM interop box.

    3> Build the addin project.

    But it's unlucky that when I run the example code to register the solution addin, I get same result as

    previously I get.

    Thanks.

    Saturday, September 21, 2013 4:56 AM
  • Hi,

    I have tested out the code above, however, the "DLL GUID " could be displayed in Visual Studio 2012.

    Here are some suggestions below:

    • Please check if the path of .dll files are correct.

    Perhaps you could do some modifications with the following code:

    Shell("C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm " & BrowseFile())
    • This issue maybe also have something to so with the way you register the addin. I think you could pay attention to Add-In Registration. The following information is about the Regasm.exe:

    Instances of classes within the assembly cannot be created from COM until they are actually registered. After registering an assembly using Regasm.exe, you can install it in the global assembly cache so that it can be activated from any COM client. For more information, please refer to Regasm.exe (Assembly Registration Tool) .

    • In addition,please clarify the version of Visual Studio in your computer.

    If you have any questions,please feel free to let me know.

    Best Regards,

    Jane.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 2:58 AM
  • Hi Jane,

    I'm using VS2008. After some debug on my project, now I can get GUID from an addin.

    But I want to know why addincoll.Count before and after Shell("regasm") are not change. Why the sample code places addincoll.Count before and after Shell("regasm").

    Thanks.

    Friday, September 27, 2013 4:53 AM
  • Hi,

    Thanks for your feedback.

    Please try to set some breakpoints in this application and check if you could see the changes in Add-in Manager when it went to addincoll.Update().

    There might exist some delay because system needs to search it from the registry first.

    Kind Regards,

    Jane.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, September 27, 2013 10:04 AM
  • Hi Jane,

    Unfortunatly, I set a breakpoint on the program, but I can not see the change in Addin-Manager after I step over addincoll.Update().

    Thanks.


    • Edited by sincos2007 Saturday, September 28, 2013 1:20 PM
    Saturday, September 28, 2013 1:19 PM
  • Hi Jane,

    I wonder whether addincoll.Update() is used for old Addin register that register an addin in registry, not for registering an addin by .Addin file used by VS2008.

    Sunday, September 29, 2013 2:56 AM
  • Thanks for your feedback.

    As mentioned in the   Add-In Registration above,after an add-in is created, it is necessary to register it to .addin file with Visual Studio before it can be activated in Add-In Manager.

    If you want to install the add-in on another computer, the .addin file must be placed in a location where Visual Studio checks for add-ins. These locations are listed in the Options dialog box, in the Environment node, on the Add-in Security page.

    Please check if you have assigned the location correctly.

    If you register it manually, however, Add-In Manager would not find the path that is not in accord with the one that was automatically created by the Add-In Wizard.

    Best Regards,

    Jane.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, September 30, 2013 5:05 AM