Switch

[TBS_BUTTON color="success" style="text-decoration:none" link="http://www.dwmkerr.com/wp-content/uploads/2013/02/SwitchSetup.zip" title="Download Switch Installer"]Download Switch Installer[/TBS_BUTTON]

Switch is an Addin for Visual Studio 2008, 2010 and 2012 that lets you quickly switch between related files. Typically you set up the Switch command somewhere easily accessible, and then just hit it everytime that you want to flick between related files. Here’s some examples of what it’ll switch between:

  1. C++ Files (cpp to h etc).
  2. WinForms Code-behind and Designer
  3. WPF/Silverlight/Windows Phone XAML and Code-behind
  4. ASPX Markup and code-behind
  5. Interface and implementation
Basically, if you are in a file that has some other kind of related file (or files) Switch will let you flick between them quickly. I originally wrote this to switch between C++ header and implementation, but find it equally useful for designers and code-behind.

Installing Switch

To install Switch, download the installer from the Switch Page on Visual Studio Gallery, or the Switch Setup zip attached to this page, and run the installer.

Visual Studio 2012 Issues

Some people have noticed that if they had the Visual Studio 2012 RC installed and then upgraded to RTM, then the installation doesn’t work for VS 2012. In this case, move the files from the Addins folder of the ‘Visual Studio 2012′ folder in your Documents directory to the ‘Addins’ folder of the ‘Visual Studio 11′ folder.

Creating a Keyboard Shortcut for Switch

To set a keyboard shortcut for the Switch command, follow these steps:

  1. In Visual Studio, you go to Tools > Customise.
  2. On the dialog that appears, choose ‘Keyboard…’.
  3. Now you have the options page open in the Keyboard section, in the ‘Show commands containing’ box, type in ‘switch’.
  4. In VS2010, you’ll see a command named ‘Switch2010.Connect.Switch2010′, in VS 2012 you’ll see ‘Switch2012.Connect.Switch2012′ – select the command and then in the box under the text ‘Press shortcut keys’, enter your shortcut key. Now press ‘Assign’ and OK.

Switch Options

If you go to Tools > Options, you’ll see a ‘Switch’ section. This section allows you to configure what you can switch between:

SwitchOptions

Get Involved

The code for Switch is available on GitHub, use the buttons below to watch, fork or follow.



Other Links

Switch is available on the Visual Studio Gallery: http://visualstudiogallery.msdn.microsoft.com/e50c0328-97a1-4842-8821-f0a82640245a

There’s an article on the CodeProject describing how to create Visual Studio Addins – this article describes how Switch was created: http://www.codeproject.com/Articles/324611/Extending-Visual-Studio-Part-2-Creating-Addins

32 Comments

  1. Hi! Nice stuff, but your Visual Studio msi package doesn’t work. I used installer from Code Project article.

    • In Visual Studio, you go to Tools > Customise.
      On the dialog that appears, choose ‘Keyboard…’.
      Now you have the options page open in the Keyboard section, in the ‘Show commands containing’ box, type in ‘switch’.
      In VS2010, you’ll see a command named ‘Switch2010.Connect.Switch2010′, in VS 2012 you’ll see ‘Switch2012.Connect.Switch2012′ – select the command and then in the box under the text ‘Press shortcut keys’, enter your shortcut key. Now press ‘Assign’ and OK – all done!

  2. Installed perfectly fine yesterday to vs2012 with update 2, but I’m having trouble with update 3 rc 2 version of the visual studio. Switch just doesn’t show up anywhere. Would be really happy, if someone can give me some kind of solution, thanks.

    • Well, found a way. Problem seem to be in the add-in paths visual studio is trying to use. For some reason, “VSMYDOCUMENTS” version probably doesn’t work as it should. If I add the path manually, it start working just fine.

  3. Thank you for the work on this addin. It is most useful for VS2012 lacking macros.

    Installed for VS2012 Update 3 RC2 with the “for everyone” option still the installer copied the files into my user folder instead of “All Users” (actually C:\ProgramData). So I copied the files manually and uninstalled switch. Now all users on the server have the addin. And I was not logged in as an Administrator upon installation and the installer asked for an administrative login – just in case this information helps.

    A great thing would be an option to disable the button in the main menu. When removing the button via the usual customization option it will reappear every startup of VS2012. As a quick fix I commented out the code adding the button to the main menu but cannot build the installer with VS2012.

  4. Thanks for the Switch add-in. Although I’ve just installed it and clicking on “Switch” does not work with solutions generated from CMake.

    I am with Visual Studio 2012 Ultimate and coding C++ and the switch works on solutions I create from Visual Studio (I’ve created a dummy solution with one class, the switch works perfectly).

    In my real projects generated from CMake the switch does nothing. Is there any chance you’d know why? Thanks in advance!

    • Hi Jean-Paul,

      I’m afraid I’ve got no experience with CMake so I’m not sure why this is happening – sorry about that! I’ll try and take a look into this for the next release though..

  5. It would be great if this was an action I could add to any tool-bar rather than it being hard-coded to appear in the main menu.

    • You can! Just go to the Customise menu and search for the ‘switch’ action (from memory, it might actually be called Switch2010 or Switch2012 depending on your VS version) – then you can drop it anywhere you like :)

  6. Switch acts a bit annoying. Let say I have “File.cpp, File.h and iFile.h”.

    Switch does:
    File.cpp -> File.h
    File.h -> iFile.h
    iFile.h -> File.h

    “Interface/implementation”-setting doesn’t have any affect on this. I don’t even have “from h to h” settings.

  7. I installed Switch for MSVS2012. The first time I start MSVS2012, I map the shortcut to CTRL+SHIFT+Q (and I can see a button on the bar, too, on the top). Everything works as advertised, I can flip forth and back – perfect.
    I close MSVS2012 and wait a bit, then start it again. The icon from the top is gone, and so is the keyboard shortcut.
    I am using MSVS2012, SP4. I wonder if there’s a compatibility problem with SP4…
    Any chance to have a look?
    Thanks a lot, this extension is a life-saver!

  8. Dave,
    Thanks a lot for this add-on. I depend on it.
    I have it assigned to a keyboard shortcut, so I don’t actually need main menu item (that shows up as “Switch” with an icon). If I remove it (by customizing main menu) it will come back after restarting VS2010. Is there anything I can do to prevent it from reappearing?

    • Hi Mike,

      Thanks for the comments – I am guessing the fact that it keeps re-appearing is probably a mistake or an invalid assumption I’ve made in the code, so I’m raising a ticket to look into this and fix it for the next release:

      https://github.com/dwmkerr/switch/issues/16

      You can track the issue there so that you’re notified when it’s done :)

  9. Please update for visual studio 2013. I realize visual studio 2013 is supposed to have baked in support for this already, but I’ve found it to be very buggy and almost never functional. Switch is the only thing keeping me sane and without it I’m going crazy pretty fast!

Leave a Reply

Your email address will not be published. Required fields are marked *