C# 将项目添加到加载项中的visual studio文件夹右键单击菜单
我想在visual studio 2012解决方案资源管理器中的右键单击=>add菜单中添加一个菜单项。单击自定义项时,我可以使用模板添加项目。 我开发了一个VisualStudio插件来实现它,但我遇到了一些麻烦。我可以将菜单项添加到右键单击菜单中,但无法使其满足我的要求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)
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());
}
}
}
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脚本”作为外部工具
- 标题:“在输出窗口中运行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)”
- 不要勾选“使用输出窗口”
- 勾选“退出时关闭”
对于您的第2个请求,您可能需要看看这篇文章。这是非常棒的定制!现在,我只需要了解如何自动执行此过程来为此编写安装程序,我将100%高兴。@C4u是否找到为此编写安装脚本的方法?@crush自动执行此操作的唯一方法是解析位于“AppData\Local”(Windows)路径中的
CurrentSettings.vssetings
文件。