Create a Visual Studio extension with a keyboard hotkey

ygoe 1 Reputation point
2022-06-05T13:27:29.77+00:00

I've just upgraded Visual Studio from 2019 to 2022 and of course a few extensions are missing again. Always the same trouble with upgrades. So I found a similar extension that already does half the work but it has no source code and the author is anonymous. I had no other choice but to disassemble its code and recreate it as a new VS extension. But something's missing that ILSpy didn't get.

The original extension is: https://marketplace.visualstudio.com/items?itemName=EngineDesigns.CollapseAllRegions
It can collapse regions but not expand them. It works by pressing the Ctrl+M, Ctrl+R hotkey.

The old extension is: https://marketplace.visualstudio.com/items?itemName=VladH.CollapseRegionExtension
It can collapse and expand regions as two separate commands with Ctrl+R, Ctrl+NumPlus and Ctrl+R, Ctrl+NumMinus. These hotkeys should be customisable in Visual Studio by the user. The source code is too old to be upgraded and the author doesn't respond anymore. So this code is probably lost and cannot be used anymore.

I disassembled the DLL of the first extension and pasted it into a new VSIX project. It's not much. It does compile but the features are not visible in the experimental instance. I guess it's because there's no code that defines the keyboard hotkeys.

I couldn't find any information about how to do that. Can anybody please explain it to me? What should I do to expose the command as a user keyboard hotkey? VS extension development is always a nightmare, way too complicated and no real documentation. And then these constant changes that break most addons. Not even Mozilla is so terrible, and they broke a lot in the past.

Oh, if somebody can make Microsoft implement this feature directly in Visual Studio and keep it there, that would be the best option. But Microsoft doesn't respond either.

Community Center Not monitored
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sergey Vlasov 266 Reputation points
    2022-06-06T05:28:37.527+00:00

    You should declare a command in a Visual Studio command table (.vsct) file.

    In the Solution Explorer, right-click the project node and select Add > New Item. In the Add New Item dialog, go to Visual C# > Extensibility and select Command.

    See https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-an-extension-with-a-menu-command?view=vs-2022

    (If the regions code is relatively simple, you can reuse it with my Visual Commander extension without creating a full extension yourself.)


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.