Dead items in context menu left by addin in Visual Studio

一曲冷凌霜 提交于 2020-01-07 04:36:13

问题


We are developing addin for Visual Studio. It creates items in Solution Explorer context menu. The problem is when we remove the addin, menu item is still there but without icon. When I click on it, VS propose to remove the command. See screenshot.

How should they be uninstalled to remove the command?
At the moment I just remove the addin file from "Visual Studio 2012\Addins" folder during uninstall.
I'm using class Connect : IDTExtensibility2


回答1:


One option is to run a .vbs script on uninstall with following commands:

Set dte = CreateObject("VisualStudio.DTE.11.0")
dte.Commands.Item("your_command_name").Delete
dte.Quit



回答2:


I've found help here.
In .addin file:

<CommandPreload>0</CommandPreload>

In Connect class:

    public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
    {
        switch (disconnectMode)
        {
            case ext_DisconnectMode.ext_dm_HostShutdown:
            case ext_DisconnectMode.ext_dm_UserClosed:
                Command command = applicationObject.Commands.Item(addInInstance.ProgID + "." + addWebDAVServerCommandId);
                if (command != null)
                {
                    command.Delete();
                }
                break;
        }
    }

    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        applicationObject = (DTE2)application;
        addInInstance = (AddIn)addInInst;

        // We should never get here, this is temporary UI
        if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            return;


来源:https://stackoverflow.com/questions/20640867/dead-items-in-context-menu-left-by-addin-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!