Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将项目添加到加载项中的visual studio文件夹右键单击菜单_C#_Visual Studio_Add In_Envdte_Project Template - Fatal编程技术网

C# 将项目添加到加载项中的visual studio文件夹右键单击菜单

C# 将项目添加到加载项中的visual studio文件夹右键单击菜单,c#,visual-studio,add-in,envdte,project-template,C#,Visual Studio,Add In,Envdte,Project Template,我想在visual studio 2012解决方案资源管理器中的右键单击=>add菜单中添加一个菜单项。单击自定义项时,我可以使用模板添加项目。 我开发了一个VisualStudio插件来实现它,但我遇到了一些麻烦。我可以将菜单项添加到右键单击菜单中,但无法使其满足我的要求 public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)

我想在visual studio 2012解决方案资源管理器中的右键单击=>add菜单中添加一个菜单项。单击自定义项时,我可以使用模板添加项目。 我开发了一个VisualStudio插件来实现它,但我遇到了一些麻烦。我可以将菜单项添加到右键单击菜单中,但无法使其满足我的要求

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());
            }
        }
    }
  • 菜单项应该是“添加”的子菜单。不是根项目

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

  • 这是我的
    OnConnection
    功能代码。如何更改它以满足我的要求

    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());
                }
            }
        }
    

    您不需要为此加载项

    链接:

    复制粘贴的博客文章

    步骤1:添加“运行powershell脚本”作为外部工具
  • 在Visual Studio中,转到菜单:工具|外部工具
  • 单击“添加”按钮
  • 添加以下表单值:

    • 标题:“在输出窗口中运行Powershell脚本”
    • 命令:“C:\windows\system32\windowspowershell\v1.0\powershell.exe”
    • 参数:“-file”$(ItemPath)
    • 初始目录:“$(ItemDir)”
    • 勾选“使用输出窗口”
    • (退出时关闭现在将自动打开)
  • 单击“应用”按钮

  • 单击“添加”按钮

  • 添加以下表单值:

    • 标题:“在VS之外运行powershell脚本”
    • 命令:“C:\windows\system32\windowspowershell\v1.0\powershell.exe”
    • 参数:“-file”$(ItemPath)
    • 初始目录:“$(ItemDir)”
    • 不要勾选“使用输出窗口”
    • 勾选“退出时关闭”
  • 单击“确定”按钮
  • 它们应该是这样的:

    第二步:奇怪的一步,相信我! 检查索引位置,它位于外部工具列表中。默认情况下,地雷位于位置6和7。(我认为默认情况下创建GUID是第一位!)

    步骤3:将其连接到上下文菜单
  • 进入菜单:工具|自定义|命令
  • 单击“上下文菜单”单选选项
  • 向下滚动至“项目和解决方案上下文菜单|项”(长菜单,键入“Proj”大致到达正确位置)
  • 单击“添加命令”按钮
  • 选择类别:“工具”和命令:“外部命令7”(或从“怪异步骤2”中获得的任何位置)
  • 点击“Ok”按钮
  • 然后设置第二个命令:
  • 选择类别:“工具”和命令:“外部命令8”(或其他位置)
  • 再次点击“确定”按钮
  • 移动它们直到你满意它们的订单(我通常把它们放在“打开…”下面的某个地方)
  • 步骤4:添加键盘快捷键
  • 进入菜单:工具|选项
  • 选择环境|键盘部分
  • 在列表中找到Tools.ExternalCommandN项(再次列出一个很长的列表,键入“Tools”再次大致显示)
  • 为每个命令选择快捷键:我喜欢CTRL SHIFT P和CTRL SHIFT 丙氨酸氨基转移酶

  • 对于您的第2个请求,您可能需要看看这篇文章。这是非常棒的定制!现在,我只需要了解如何自动执行此过程来为此编写安装程序,我将100%高兴。@C4u是否找到为此编写安装脚本的方法?@crush自动执行此操作的唯一方法是解析位于“AppData\Local”(Windows)路径中的
    CurrentSettings.vssetings
    文件。