Studio文件夹的AddIn右键菜单中

Studio文件夹的AddIn右键菜单中

本文介绍了将项目添加到Visual Studio文件夹的AddIn右键菜单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Visual Studio 2012解决方案资源管理器中右键单击=>添加菜单项。单击自定义项时,我可以添加带有模板的项目。
我开发了一个Visual Studio加载项来执行此操作,但遇到了一些麻烦。我可以在右键菜单中添加一个菜单项,但无法满足我的要求。


    该菜单项应为添加的子菜单。不是根项目。


    我还需要仅在右键单击名为 Areas的文件夹时显示菜单项。我不希望在右键单击其他文件夹时显示它。


这是我的 OnConnection 功能代码。

  public void OnConnection(对象应用程序,ext_ConnectMode connectMode,对象addInInst,引用数组自定义) )
{
_applicationObject =(DTE2)application;
_addInInstance =(((AddIn)addInInst);
if(connectMode == ext_ConnectMode.ext_cm_UISetup)
{
object [] contextGUIDS = new object [] {};
Commands2命令=(Commands2)_applicationObject.Commands;

//将命令放在工具菜单上。
//找到MenuBar命令栏,它是包含所有主菜单项的顶级命令栏:
var bars =(((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars);

Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = bars [ MenuBar];

//在MenuBar命令栏上找到Tools命令栏:
// CommandBarControl toolsControl = menuBarCommandBar.Controls [toolsMenuName];
// CommandBarPopup toolsPopup =(CommandBarPopup)toolsControl;
//获取将在其中注册命令的popUp命令栏。
CommandBars cmdBars =(CommandBars)(_ applicationObject.CommandBars);
// CommandBar vsBarItem = cmdBars [ Item]; //单击一个项目的弹出窗口项
CommandBar vsBarFolder = cmdBars [ Web Project Folder];
CommandBar vsBarWebFolder = cmdBars [ Web文件夹];

//如果您希望添加多个由外接程序处理的命令,则可以复制此try / catch块,
//仅确保还更新了QueryStatus / Exec新命令名称的方法。
try
{
//将命令添加到Commands集合:
Command command =命令。AddNamedCommand2(_addInInstance, ModuleAddin,添加项目,执行用于ModuleAddin的命令,是,真,59,参考contextGUIDS,(int)vsCommandStatus.vsCommandStatusSupported +(int)vsCommandStatus.vsCommandStatusEnabled,(int)vsCommandStyle.vsCommandStylePictAndText,vsCommandControlType.vsCommandControlTypeButton);
//将命令控件添加到工具菜单:
if(command!= null)
{
//command.AddControl(toolsPopup.CommandBar,1);
command.AddControl(vsBarFolder);
// CommandBarButton按钮=(CommandBarButton)command.AddControl(vsBarFolder,3);
//button.BeginGroup = true;
}
}
catch(System.ArgumentException argEx)
{
System.Diagnostics.Debug.Write( HintPaths中的异常: + argEx.ToString() );
}
}
}


解决方案

您不需要为此的加载项。



链接:



第2步:奇怪的步骤,相信我!



检查索引位置在外部工具列表中。默认情况下,我的位置是6和7。(我认为默认情况下,创建GUID是1号!)



步骤3:将其连接到上下文菜单




    转到菜单:工具|自订|命令
    单击上下文菜单单选选项
    向下滚动到项目和解决方案上下文菜单|项目(噩梦长菜单,键入 Proj以大致找到正确的位置)
    单击添加命令按钮
    选择类别:工具和命令:外部命令7(或您从怪异的第2步获得的位置是什么)
    点击确定按钮
    然后设置第二个命令:
    选择类别:工具,然后选择命令:外部命令8(或您在另一个位置的位置)
    再次点击确定按钮
    移动它们,直到您对它们的顺序满意为止(我通常将它们放在打开方式...下方的位置)



步骤4:添加键盘快捷键




    转到菜单:工具|选项
    选择环境|键盘部分
    在列表中找到Tools.ExternalCommandN项(再次是噩梦般的长列表,键入工具使您再次大致到达该位置)
    选择每个命令的快捷键:我喜欢 和



I want to add a menuitem to the right-click=>Add menu in visual studio 2012 solution explorer. When click the custom item I can add a project with my template.I developed a Visual Studio Add-In to do it but I get into some trouble. I am able to add a menuitem to the right-click menu but I can't get it to meet my requirement.

    The menuitem should be the submenu of "Add". Not a root item.

    I also need the menuitem to show only when I right-click on a folder named "Areas". I don't want it to show when I right-click on other folders.

Here is my OnConnection function code. How can I change it to meet my requirement.

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;
        _addInInstance = ((AddIn)addInInst);
        if (connectMode == ext_ConnectMode.ext_cm_UISetup)
        {
            object[] contextGUIDS = new object[] { };
            Commands2 commands = (Commands2)_applicationObject.Commands;

            //Place the command on the tools menu.
            //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
            var bars=((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars);

            Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = bars["MenuBar"];

            //Find the Tools command bar on the MenuBar command bar:
            //CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
            //CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
            // get popUp command bars where commands will be registered.
            CommandBars cmdBars = (CommandBars)(_applicationObject.CommandBars);
            //CommandBar vsBarItem = cmdBars["Item"]; //the pop up for clicking a project Item
            CommandBar vsBarFolder = cmdBars["Web Project Folder"];
            CommandBar vsBarWebFolder = cmdBars["Web Folder"];

            //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
            //  just make sure you also update the QueryStatus/Exec method to include the new command names.
            try
            {
                //Add a command to the Commands collection:
                Command command = commands.AddNamedCommand2(_addInInstance, "ModuleAddin", "Add a Project", "Executes the command for ModuleAddin", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                //Add a control for the command to the tools menu:
                if (command != null)
                {
                    //command.AddControl(toolsPopup.CommandBar, 1);
                    command.AddControl(vsBarFolder);
                    //CommandBarButton button = (CommandBarButton)command.AddControl(vsBarFolder, 3);
                    //button.BeginGroup = true;
                }
            }
            catch (System.ArgumentException argEx)
            {
                System.Diagnostics.Debug.Write("Exception in HintPaths:" + argEx.ToString());
            }
        }
    }
解决方案

You don't need an add-in for this.

Link: http://nickmeldrum.com/blog/how-to-run-powershell-scripts-from-solution-explorer-in-visual-studio-2010

Copy-pasted blog post...

这篇关于将项目添加到Visual Studio文件夹的AddIn右键菜单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:32