Adding a Visual Studio Toolbar Button for a Command Available Only as a Shortcut

This question relates to this ReSharper YouTrack issue .

In Visual Studio 2010 with ReSharper 7.1.1 installed, if I go to Tools> Options> Environment> Keyboard, the ReSharper_SilentCleanupCode command will appear.

I would like to bind this command to a button on the toolbar.

This seems impossible using Tools> Customize> Commands, because the only commands available in this dialog box are for actions that already have an associated menu item. The specific ReSharper command that I am interested in (Silent Code Cleanup) does not appear in any menu, so it cannot be assigned to a toolbar button using the "GUI".

Is there any other way to attach only the keyboard to a button on the toolbar? (One of the ReSharper programmers thought it was possible to use the "VS script editor", but I was not lucky to find information about this.)

Edit

I should have mentioned this first. Although the azhrei macro solution is great for Visual Studio 2010, it will break after upgrading to VS 2012 because macros are no longer supported. If someone has a solution that will continue to work in VS 2012, that would be preferable. (Or maybe VS 2012 toolbars don't have the same limitation in the first place?)

+4
source share
1 answer

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

This works because the command line command is displayed in the Macros menu of the Customize Commands dialog box.

More details

Add a macro that does the following:

Sub _ReSharper_SilentCleanupCode() DTE.ExecuteCommand("ReSharper_SilentCleanupCode") End Sub 

Place this macro in the module that appears in the setting ..Commands..AddCommand..Categories..Macros, for example Samples or MyMacros.RecordingModule, but not MyMacros.Module1 (by default when using the IDE macro).

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

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

Select the Macros.Samples._ReSharper_SilentCleanupCode macro.

Click Modify Selection and change the name to #-) or to any other text that makes you think that ReSharper Silent Code Cleanup will not be too long for your toolbar .:-)

I tried this with Visual Studio 2010 and ReSharper 7.1.2.

Edit

Visual Commander is apparently the way to get this on VS2012 - see comments below for more.

+4
source

Source: https://habr.com/ru/post/954767/


All Articles