【问题标题】:Get Project form "Project" CommandBar button获取项目表单“项目”命令栏按钮
【发布时间】:2014-07-07 13:38:12
【问题描述】:

我正在为 VS 2012 开发一个插件。我在Project 命令栏中添加了一个按钮和命令。

现在我在点击Project 后右键菜单中有按钮。

我现在要做的就是列出项目中单击该按钮的所有*.cs 文件,并有权对其进行编辑。

我需要在“执行”函数中“捕获”我的命令的信息。

怎么做?

我的代码片段:

_CommandBars cmdBars = (_CommandBars)_applicationObject.CommandBars;

CommandBar vsBarProject = cmdBars["Project"];

CommandBarPopup pluginProjectFolderPopup = (CommandBarPopup)vsBarProject.Controls.Add(MsoControlType.msoControlPopup, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, true);

pluginProjectFolderPopup.Caption = "Plugin";

try
{
    Command command = commands.AddNamedCommand2(_addInInstance, "TestRightClickProject", "Plugin test", "Testing right click command on code window", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);
    if ((commands != null) && (pluginProjectFolderPopup != null))
    {
        command.AddControl(pluginProjectFolderPopup.CommandBar, 1);
    }
}
catch (System.ArgumentException)
{
}

更新: 我别无选择。我必须使用插件

【问题讨论】:

  • (相关警告:Visual Studio 的下一个版本(目前称为 Visual Studio “14”)不支持加载项。您可能需要考虑编写扩展程序。)
  • @RichieHindle 我别无选择。我必须使用插件

标签: c# .net add-in visual-studio-addins


【解决方案1】:

看看这个问题的答案:

Visual Studio 2010 Plug-in - Adding a context-menu to the Solution Explorer

一旦您确定要选择的项目(请参阅

_applicationObject.SelectedItems.Item(1).Project

)

您可以使用 ProjectKinds.vsProjectKindSolutionFolder 来获取项目文件夹(请参阅 How to get folders under projects?)

然后遍历所需的文件夹和子文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    相关资源
    最近更新 更多