【发布时间】:2012-12-18 13:39:51
【问题描述】:
您能否对 VS2012 中的 .SLN/.CSPROJ 文件做一些事情,这样当您在解决方案资源管理器中右键单击解决方案/项目时,上下文菜单上会出现一个运行您指定的工具的新项目?
我知道您可以将自定义条目添加到“工具”菜单,但在这种情况下,这些工具是特定于该特定解决方案的。
【问题讨论】:
标签: visual-studio-2012 extensibility
您能否对 VS2012 中的 .SLN/.CSPROJ 文件做一些事情,这样当您在解决方案资源管理器中右键单击解决方案/项目时,上下文菜单上会出现一个运行您指定的工具的新项目?
我知道您可以将自定义条目添加到“工具”菜单,但在这种情况下,这些工具是特定于该特定解决方案的。
【问题讨论】:
标签: visual-studio-2012 extensibility
您可以通过插件将按钮添加到Solution 上下文菜单,如下所示:
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["Solution"];
try
{
//Add a command to the Commands collection:
Command command = commands.AddNamedCommand2(_addInInstance, "MyAddinMenuBar", "MyAddinMenuBar", "Executes the command for MyAddinMenuBar", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
//Add a control for the command to the solution context menu:
if (command != null)
{
command.AddControl(menuBarCommandBar, 1);
}
}
catch (System.ArgumentException)
{
// safely ignore the exception.
}
不同解决方案的工具规范应由您的插件在内部处理。您可以提取解决方案的完整路径(来自_applicationObject.Solution.FullName)以及包含的项目的属性(来自_applicationObject.Solution.Projects)。
如果您使用的是VSPackage,您应该定义一个vsct 文件来添加命令和菜单项。
【讨论】: