Summary
Microsoft.VisualStudio.Extensibility.Commands.Key exposes top-row numeric keys
(D0–D9 and VK_0–VK_9), but current Visual Studio command hosting does
not accept them for CommandShortcutConfiguration.
Environment
- Visual Studio 18.8.12023.21
- Microsoft.VisualStudio.Extensibility 17.14.2098
- Microsoft.VisualStudio.Extensibility.Sdk / Build 17.14.40608
- Out-of-process
net8.0-windows extension
Minimal repro
[VisualStudioContribution]
internal sealed class TestCommand : Command
{
public TestCommand(VisualStudioExtensibility extensibility)
: base(extensibility)
{
}
public override CommandConfiguration CommandConfiguration => new("Test")
{
Shortcuts =
[
new CommandShortcutConfiguration(
ModifierKey.ControlLeftAlt,
Key.D1)
]
};
public override Task ExecuteCommandAsync(
IClientContext context,
CancellationToken cancellationToken) => Task.CompletedTask;
}
Actual result
The generated extension.json contains:
{
"mod1": "ControlLeftAlt",
"key1": "1"
}
The shortcut is not correctly registered/displayed as Ctrl+Alt+1.
Using Key.VK_1 generates "key1": "VK_1" and causes the command set to fail
registration; its context menu disappears.
Decompiled cause
Microsoft.VisualStudio.Shell.UI.Internal.dll parses shortcut keys as:
Key1 = (byte)Enum.Parse(typeof(KnownKey), key1);
Its internal KnownKey enum does not define D0–D9 or VK_0–VK_9, but
does define VK_NUMPAD0–VK_NUMPAD9.
Expected result
Key.D1 should bind the top-row 1 key.
Key.VK_1 should bind virtual key 0x31.
- Invalid shortcut metadata should not make unrelated menus disappear.
Workaround
NumPad keys work:
new CommandShortcutConfiguration(
ModifierKey.ControlLeftAlt,
Key.VK_NUMPAD1)
The public API documents Key as valid for command shortcuts:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.extensibility.commands.key?view=vs-extensibility
This is a solid SDK/host compatibility bug: the public contract advertises keys that the Visual Studio host cannot parse.
Summary
Microsoft.VisualStudio.Extensibility.Commands.Keyexposes top-row numeric keys(
D0–D9andVK_0–VK_9), but current Visual Studio command hosting doesnot accept them for
CommandShortcutConfiguration.Environment
net8.0-windowsextensionMinimal repro
Actual result
The generated
extension.jsoncontains:{ "mod1": "ControlLeftAlt", "key1": "1" }The shortcut is not correctly registered/displayed as
Ctrl+Alt+1.Using
Key.VK_1generates"key1": "VK_1"and causes the command set to failregistration; its context menu disappears.
Decompiled cause
Microsoft.VisualStudio.Shell.UI.Internal.dllparses shortcut keys as:Its internal
KnownKeyenum does not defineD0–D9orVK_0–VK_9, butdoes define
VK_NUMPAD0–VK_NUMPAD9.Expected result
Key.D1should bind the top-row1key.Key.VK_1should bind virtual key0x31.Workaround
NumPad keys work:
The public API documents Key as valid for command shortcuts:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.extensibility.commands.key?view=vs-extensibility
This is a solid SDK/host compatibility bug: the public contract advertises keys that the Visual Studio host cannot parse.