Problem trying to create ssms add-in

I am trying to create an add-in for SSMS 2008 and / or 2008 R2, but I immediately ran into a problem.

I can make my add-in work, and when I start SSMS just show a message box.

However, after loading various code samples, when I try to reference Microsoft.SqlServer.Management.UI.VSIntegration.ServiceCache, I get an exception with a null reference:

Commands2 commands = (Commands2)ServiceCache.ExtensibilityModel.Commands;

I get this problem when using SSMS 2008 or SSMS 2008 R2. I am working on Visual Studio 2010.

This is a little disappointing because I really want to learn more about SSMS add-ons, but I can't seem to get past a few samples.

Any tips / advice appreciated.

thank

+3
source share
6

ServiceCache - , , , , - .

SSMS, , VS ApplicationModel. - :

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _addInInstance = (AddIn)addInInst;
            _applicationObject = _addInInstance.DTE as DTE2;

_applicationObject .

:, OnConnection , . : _applicationObject = _addInInstance.DTE DTE2;

+3

.

, sql 2008 - VS2008.

VS2010 sql 2008 r2 - .

; * . * . .

. VS2008, . (. : http://sqlblog.com/blogs/jonathan_kehayias/archive/2009/08/22/sql-2008-r2-breaks-ssms-addins.aspx)

!!

+1

, , CLR2.0 CLR 4.0

: http://blogs.msdn.com/b/mshneer/archive/2010/03/19/com-shim-wizards-for-vs-2010.aspx

CLR 2.0 Visual Studio 2010

CLR 2.0. F5, Excel , . , , , F5 .

, - , . OnConnection Connect.cs, , "", " " (, "C:\Program Files\Microsoft Office\Office12\EXCEL.EXE" ). node " Startup Project". F5, .

Visual Studio 2010 , CLR 2.0. , , CLR 4.0 CLR 2.0 - , CLR 2.0 CLR 4.0 . F5 , CLR . EXE.config, 8 .config CLR 4.0 . CLR .

- .exe.config .exe. Excel 2007 Excel.exe.config "C:\Program Files\Microsoft Office\Office12".

. node "" → " " "C:\Program Files\Microsoft Office\Office12\EXCEL.EXE". " " ". " "" (v2.0, v1.1, v1.0)". F5 , OnConnection.

+1

. , Framework

Framework 3.5

ServiceCache.ExtensibilityModel

Framework 4.0

"ServiceCache.ExtensibilityModel" -

0

, , Framework 3.5, VS2010 . Framework 4, VS2010 . CreateToolWindow2 , !

:

    /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
    /// <param term='application'>Root object of the host application.</param>
    /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
    /// <param term='addInInst'>Object representing this Add-in.</param>
    /// <seealso class='IDTExtensibility2' />
    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {            
       _addInInstance = (AddIn)addInInst;
       _applicationObject = (DTE2)_addInInstance.DTE;

       if (connectMode == ext_ConnectMode.ext_cm_Startup)//ext_ConnectMode.ext_cm_UISetup)
       {
       }        
    }

    /// <summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary>
    /// <param term='custom'>Array of parameters that are host application specific.</param>
    /// <seealso class='IDTExtensibility2' />
    public void OnStartupComplete(ref Array custom)
    {            
       Windows2 win2 = this._applicationObject.Windows as Windows2;

       if (win2 != null)
       {
           Assembly asm = Assembly.GetExecutingAssembly();
           AddIn addinobj;

           addinobj = this._applicationObject.AddIns.Item(1);

           object controlObject = null;

           Guid id = new Guid("4c410c93-d66b-495a-9de2-99d5bde4a3b9"); // this guid doesn't seem to matter?
           //Window                 
           Window windowTool = win2.CreateToolWindow2(addinobj,
                                                      asm.Location,
                                                      "MyAddinASupp.UserControl1",    "Zone de test", 
                                                      "{" + id.ToString() + "}",
                                                      ref controlObject);

          windowTool.Visible = true;
       }
    }
0

Source: https://habr.com/ru/post/1747672/


All Articles