Thursday, May 3, 2012

Set Visual Studio 2010 Shortcuts Using Powershell

The awesome things you can do with the $dte object inside Visual Studio 2010 just keep piling up. I could not find any examples on how to do it with Powershell.

You can list the commands and their bindings with the following command. Important note... there are a LOT of commands and it will likely take several seconds to output everything.
$dte.Commands | ft -Property Name, Bindings

If you already know the command name, you can get the bindings using the following command.
$dte.Commands | ? { $_.Name -eq "View.TfsSourceControlExplorer" } | % {
    $_.Bindings;
}

Be careful to not choose a shortcut that is already in use. The following are some bindings that I find very useful. The first sets a convenient way to open the Source Control Explorer.
$dte.Commands | ? { $_.Name -eq "View.TfsSourceControlExplorer" } | % {
    $_.Bindings = "Global::Ctrl+W, Ctrl+1";
}

This opens the folder in Windows Explorer containing the current file.
$dte.Commands | ? { $_.Name -eq "File.OpenContainingFolder" } | % {
    $_.Bindings = "Global::Ctrl+Shift+Alt+O";
}

This opens the Attach to Process... dialog. I can't remember if this is the default shortcut, but here it is regardless.
$dte.Commands | ? { $_.Name -eq "Tools.AttachtoProcess" } | % {
    $_.Bindings = "Global::Ctrl+Alt+P";
}

No comments: