为仅可用作键盘快捷键的命令添加 Visual Studio 工具栏按钮

dev*_*xer 5 resharper visual-studio-2010 visual-studio resharper-7.1

这个问题与这个ReSharper YouTrack 问题有关

在安装了 ReSharper 7.1.1 的 Visual Studio 2010 中,如果我转到“工具”>“选项”>“环境”>“键盘”,则会有一个名为 ReSharper_SilentCleanupCode 的命令。

我想将此命令绑定到工具栏按钮。

使用工具 > 自定义 > 命令似乎不可能做到这一点,因为此对话框中唯一可用的命令是针对已具有关联菜单项的操作。我感兴趣的特定 ReSharper 命令(Silent Code Cleanup)没有出现在任何菜单中,因此无法使用“GUI”将其分配给工具栏按钮。

有没有其他方法可以将仅键盘命令绑定到工具栏按钮?(ReSharper 的一位程序员认为可以使用“VS 脚本编辑器”,但我没有找到这方面的信息。)

编辑

我应该首先提到这一点。虽然 azhrei 的宏解决方案非常适合 Visual Studio 2010,但一旦我升级到 VS 2012,它就会崩溃,因为不再支持宏。如果有人有一个可以在 VS 2012 中继续工作的解决方案,那会更好。(或者也许 VS 2012 工具栏一开始就没有相同的限制?)

azh*_*rei 5

Add a macro that executes the command, then add the macro to a toolbar.

This works because it makes the keyboard-only command appear in the Macros menu in the Customize Commands dialog.

Details

Add a macro which does this:

    Sub _ReSharper_SilentCleanupCode()
        DTE.ExecuteCommand("ReSharper_SilentCleanupCode")
    End Sub
Run Code Online (Sandbox Code Playgroud)

Put this macro in a module which appears in Customize..Commands..AddCommand..Categories..Macros, such as Samples or MyMacros.RecordingModule, but not MyMacros.Module1 (the default when using the macro IDE).

Go to Tools..Customize..Command and select the Toolbar you want.

Now Add Command... and select the Macros category.

Select your Macros.Samples._ReSharper_SilentCleanupCode macro.

Click Modify Selection and change the name to #-) or whatever text makes you think ReSharper Silent Code Cleanup without being too long for your toolbar. :-)

I tried this with Visual Studio 2010 and ReSharper 7.1.2.

Edit

Visual Commander is a apparently way to get this going on VS2012 as well - see comments below for more.