尝试创建 ssms 加载项时出现问题

发布于 2024-09-03 14:20:49 字数 453 浏览 4 评论 0 原文

我正在尝试为 SSMS 2008 和/或 2008 R2 创建加载项,但我立即遇到了问题。

我可以让我的加载项正常工作,并在 SSMS 启动时让它仅显示一个消息框。

但是,下载各种代码示例后,在尝试引用 Microsoft.SqlServer.Management.UI.VSIntegration.ServiceCache 时,出现空引用异常:

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

使用 SSMS 2008 或 SSMS 2008 R2 时遇到此问题。我正在使用 Visual Studio 2010。

这有点令人沮丧,因为我很想了解有关 SSMS 加载项的更多信息,但似乎无法超越那里的几个示例。

任何建议/提示表示赞赏。

谢谢

I'm trying to create an add-in for SSMS 2008 and/or 2008 R2 but I've run into a problem straight away.

I can get my add-in to work and on SSMS start-up get it to simply show a message box.

However, after downloading various code-samples, when trying to reference Microsoft.SqlServer.Management.UI.VSIntegration.ServiceCache I get a null reference exception:

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

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

It's a bit frustrating because I'm keen to learn more about SSMS add-ins but can't seem to get past the few samples out there.

Any advice/tips appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

只有影子陪我不离不弃 2024-09-10 14:20:49

Karl,我不知道你在这里的具体问题,但回答另一个问题时,我发现了一堆关于编写 SSMS 插件的文章和链接 - 也许其中一篇对你有用:

可以在这里找到一些信息:

Karl, I don't know about your concrete problem here, but answering another question, I came across a bunch of articles and links on writing SSMS plug-ins - maybe one of them will be useful to you:

Some information can be found here:

多情癖 2024-09-10 14:20:49

ServiceCache 是不可靠的——从一个版本到另一个版本,它支持的越来越少,并且可能会在某个时候消失。

如果您编写SSMS Add-in,则可以通过访问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 的 application 参数传入了不正确的对象。这就是为什么您必须使用此行来获取正确的对象:_applicationObject = _addInInstance。 DTE 为 DTE2;

ServiceCache is unreliable - from version to version it supports less and less and probable will go away at some point.

If you write SSMS Add-in, you can access internals by accessing VS ApplicationModel.
Something like that:

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

_applicationObject has Commands and other interesting stuff.

Please note, that application argument of OnConnection has an incorrect object passed in. That's why you have to use this line to get the right object: _applicationObject = _addInInstance.DTE as DTE2;

一个人的旅程 2024-09-10 14:20:49

我已经为此苦苦挣扎了一段时间。

我有一个在 sql 2008 中工作的插件 - 用 VS2008 编写。

我将项目升级到 VS2010 并开始致力于让 sql 2008 r2 加载项正常工作 - 我无法因为爱和金钱而让它工作。

我尝试了很多不同的事情;
* 删除并重新添加所有引用。
* 改变目标框架。
不是香肠。

没有任何效果....
直到我回到 VS2008 - 我进行了更改。 (请参阅 Jonathan Kehayias 博客:https://www.sqlskills.com/blogs/jonathan/sql-server-2012-extended-events-add-in-to-manage-2008r2-instances/

万岁新版本!!

I've been struggling with this for a while.

I've got an add-in what work in sql 2008 - written in VS2008.

I upgraded the project to VS2010 and started working on getting the sql 2008 r2 add-in working - I could not get this working for love nor money.

I tried lots of different things;
* deleting and re-adding all the references.
* changing the target framework.
Not a sausage.

Nothing worked....
Until I went back to VS2008 - I made the changes. (see Jonathan Kehayias blog: https://www.sqlskills.com/blogs/jonathan/sql-server-2012-extended-events-add-in-to-manage-2008r2-instances/)

Hurray for new versions!!

琴流音 2024-09-10 14:20:49

好的,我找到解决方案,问题出在 CLR2.0 和 CLR 4.0 之间

来源:http://blogs.msdn.com/b/mshneer/archive/2010/03/19/com-shim-wizards-for-vs-2010.aspx< /a>

调试针对 CLR 2.0 的加载项
Visual Studio 2010

我在调试加载项时遇到了一些问题
如果那些在 CLR 2.0 中加载。我
按 F5,Excel 将启动
我的加载项会运行,但是
断点没有被击中。所以我
想分享正在发生的事情并且
如何设置你的环境
F5 体验并非如此
完全损坏了。

我通常的方式没有魔法
继续调试共享加载项 -
有垫片或无垫片。我设置了一个
OnConnection 方法中的断点
在 Connect.cs 文件中,打开项目的
属性,转到调试部分,
选择“启动外部程序”
选项并将完整路径设置为我的
Office 应用程序(例如“C:\Program
文件\微软
Office\Office12\EXCEL.EXE")。接下来我
右键单击项目节点
解决方案资源管理器并选择“设置为
启动项目”。当我按 F5 时
断点被击中。

在 Visual Studio 2010 中断点
如果加载我的加载项则不会被命中
CLR 2.0。到底是怎么回事
调试器无法同时连接到 CLR 4.0
和 CLR 2.0 - 它实际上需要
事前知道是否应该
使用 CLR 2.0 调试引擎或
CLR 4.0 调试引擎。当你
按 F5 调试器尝试猜测哪个
CLR 将在此过程中启动。
启发式基于阅读
EXE 的 .config 文件(需要时)
运行时版本是 u8sually 指定的
如果找不到 .config 文件
比调试器启动 CLR 4.0
调试引擎。众所周知
Office申请不受约束
CLR 的任何特定版本
启发式惨遭失败。

其实有两种处理方式
有了它——一个是放一个
.exe.config 文件并排
.exe 本身,例如调试时
我将创建 Excel 2007
Excel.exe.config 并将其保留在
“C:\Program Files\Microsoft
Office\Office12”文件夹。

但我更喜欢的处理方式
这是不同的。在解决方案中
资源管理器我将右键单击我的
解决方案节点并选择“添加”->
“现有项目”并打开
“C:\Program Files\Microsoft
Office\Office12\EXCEL.EXE”。接下来,我
右键单击这个新添加的
项目并选择“设置为启动
项目”。接下来,我将打开
该项目的属性并将
将“调试器类型”属性设置为
“托管(v2.0、v1.1、v1.0)”。现在,我
将 F5 和我设置的断点
OnConnection 方法将被命中。

Ok I find solution, the problem is between CLR2.0 and CLR 4.0

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

Debugging add-ins targeting CLR 2.0 in
Visual Studio 2010

I had some problems debugging add-ins
if those were loading in CLR 2.0. I
would press F5, Excel would start up
and my add-in would run but the
breakpoints were not getting hit. So I
wanted to share what's going on and
how to set up your environment in such
a way that F5 experience is not
completely broken.

There is no magic in the way I usually
go about debugging the shared add-in -
either shimmed or unshimmed. I set a
breakpoint in the OnConnection method
in Connect.cs file, open project's
properties, go to the Debug section,
select the "Start External Program"
option and set the full path to my
Office application (e.g. "C:\Program
Files\Microsoft
Office\Office12\EXCEL.EXE"). Next I
right click on the project node in the
Solution Explorer and select "Set As
Startup Project". When I press F5 my
breakpoint is hit.

In Visual Studio 2010 the breakpoint
is not hit if my add-in is loaded in
CLR 2.0. What's going on is that
debugger cannot attach to both CLR 4.0
and CLR 2.0 - it actually needs to
know before the fact whether it should
be using CLR 2.0 debugging engine or
CLR 4.0 debugging engine. When you
press F5 debugger tries to guess which
CLR will be started in the process.
The heuristic is based on reading the
EXE's .config file where required
runtime version is u8sually specified
and if the .config file is not found
than the debugger fires up the CLR 4.0
debugging engine. As we all know
Office application are not bound to
any particular version of the CLR so
the heuristic miserably fails.

There are actually two ways of dealing
with it – one is to put an
.exe.config file alongside
the.exe itself e.g. when debugging
Excel 2007 I will create
Excel.exe.config and leave it in the
"C:\Program Files\Microsoft
Office\Office12" folder.

But my preferred way of dealing with
this is different. In the Solution
Explorer I will right click on my
solution node and select "Add" ->
"Existing Project" and open
"C:\Program Files\Microsoft
Office\Office12\EXCEL.EXE". Next, I
will right click on this newly added
project and select "Set As Startup
Project". Next, I will open the
properties for this project and will
set the "Debugger Type" property to
"Managed (v2.0, v1.1, v1.0)". Now, I
will F5 and the breakpoint I've set in
OnConnection method will be hit.

苏辞 2024-09-10 14:20:49

我有同样的问题。我认为它更喜欢 Framework

3.5

ServiceCache.ExtensibilityModel 不为空

对于 Framework 4.0,

“ServiceCache.ExtensibilityModel”是

I've the same problem. I think that it's liked to the Framework

With Framework 3.5

ServiceCache.ExtensibilityModel is not null

With Framework 4.0

"ServiceCache.ExtensibilityModel" is
null

樱桃奶球 2024-09-10 14:20:49

好的,谢谢你的这种方式,但是如果我有一个 Framework 3.5 中的项目,VS2010 不会在我的断点处停止。
但是如果我将Framework更改为4,VS2010就会在断点处停止。但 CreateToolWindow2 引发异常,因为不是同一个 Framework !

我将代码简化为最少:

    /// <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;
       }
    }

Ok, thanks for this way, but if I have a project in Framework 3.5, VS2010 doesn't stop on my break point.
But if I change the Framework to 4, VS2010 stop on the breakpoint. But CreateToolWindow2 raise an exception, because isn't the same Framework !

I simplify the code as minimum :

    /// <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;
       }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文