Visual Studio 2013 Cookbook

4.5 (2 reviews total)
By Jeff Martin , Richard Banks
  • Instant online access to over 8,000+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Discovering Visual Studio 2013

About this book

Visual Studio 2013 is the premier tool for developers targeting the Microsoft platform. Learning how to effectively use this technology can enhance your productivity while simplifying your most common tasks, allowing you more time to focus on your project.

Visual Studio 2013 Cookbook will introduce you to all the new areas of Visual Studio and how they can quickly be put to use to improve your everyday development tasks. With this book, you will learn not only what VS2013 offers, but what it takes to put it to work for your projects.

Updated and expanded for VS2013, this book begins by introducing you to the interface changes to Visual Studio and then moves on to demonstrate how VS2013 can be used for developing desktop, mobile, and web applications. This book provides a comprehensive overview of all areas of Visual Studio. This practical approach will benefit you greatly if you are a newcomer but also if you want a tour of what the latest edition of Visual Studio has to offer. The recipes in this book provide useful examples of VS2013 which can help you whether you are targeting the Web, mobile devices, or the traditional Windows desktop.

Publication date:
March 2014


Chapter 1. Discovering Visual Studio 2013

In this chapter, we will cover:

  • Synchronizing settings

  • Touring the VS2013 IDE

  • Project round-tripping

  • Managing the editor windows

  • Finding Visual Studio commands

  • Searching and navigating

  • Navigating in depth



The arrival of Visual Studio 2013 (VS2013) marks the continuation of Microsoft's desire to produce more frequent updates to the Visual Studio platform. If you are coming to VS2013 from VS2012, you will find a more familiar appearance. Users upgrading to VS2013 from VS2010 will find greater differences and need to spend a bit more time learning the new interface. This chapter will provide a walk-through of the major changes and explain how VS2013's IDE will benefit you, regardless of the languages you are programming with.

VS2013 has focused a great deal on improving the usability and the power of the editor and surrounding windows that you use every day in your work. Before exploring specific features that apply only to certain areas, this chapter examines how the IDE can benefit your work regardless of whether you write C++ console applications or use JavaScript to write Windows Store apps.

The goal of this chapter is to provide you with an overview of the IDE-related features of VS2013. The chapter will begin by describing the integration of Microsoft accounts with the IDE and the value that this can provide. Next comes a review of the IDE, with a focus on the new features found in VS2013. Realizing that in the real world, circumstances can require supporting pre-VS2013 projects, we'll look at how Visual Studio utilizes project round-tripping to enable working with these older project types. The chapter will then wrap up with a couple of recipes on day-to-day editing and navigation tips designed to increase your productivity. Like any set of complex tools, an initial investment in learning the nuances can provide lasting dividends.


Synchronizing settings

One of the first things that you will notice upon opening VS2013 is the request to log in with a Microsoft account. You can use any existing Microsoft account that you have, including Outlook/Hotmail, OneDrive (formerly known as SkyDrive), and Xbox Live. If you have an MSDN account, Microsoft recommends that you use it to log in to Visual Studio. If you don't, or if you would prefer to use a new account, you can create one at Microsoft groups the settings by product type, so there is one set of roaming settings linked to all editions of Visual Studio Professional, Premium, and Ultimate. A separate set of settings is synched across the Express editions of Visual Studio. The result is that the settings saved for VS Express 2013 for Windows will not sync when you log in to VS2013 Professional.

In this recipe, we will look at how this synchronization works and what it will coordinate on your behalf.

Getting ready

To explore, launch your copy of Visual Studio 2013.

How to do it…

If you are not prompted to sign in at startup, you can always sign in from within Visual Studio. The arrow in the following screenshot indicates where the Sign in option is located:

Currently, VS2013 will sync options from the following categories:

  • Environment : This section consists of several subitems:

    • Fonts and Colors: This includes preferences for the text used throughout the editor

    • Color theme of IDE: This provides built-in themes including light/dark/blue

    • Keyboard: This includes user-defined keyboard shortcuts and the selected keyboard-mapping scheme

    • Startup: This indicates what should display when VS2013 opens

  • Text Editor: A multitude of settings including tabs versus spaces, word wrap, scroll bar placement, and so on

  • Environment Aliases: (Not shown, applies to premium versions only) Commands defined in the command window (Ctrl + Alt + A)

    The following screenshot highlights the synchronized categories:


The Options dialog box in VS2013 has a couple of usability enhancements. First, it has its own integrated search box (once Options is opened, the hotkey is Ctrl + E) for specifically searching within the Options dialog box. Second, the dialog is now resizable, making it much more useful for viewing settings that have lengthy configuration options.

How it works…

Microsoft stores a copy of your settings on their servers. A constant Internet connection is not required to use Visual Studio, but your settings will not synchronize until you are reconnected. If a connection is not available, you cannot login until Internet access is restored, but Visual Studio will still be usable. Taking it one step further, VS2013 remembers if you were logged in the last time when you closed the program, so your last known settings will be available as they are stored locally.

There's more…

All synchronization options are configurable by navigating to Options | Environment | Synchronized Settings, and you may opt to have any combination of the preceding categories synched. This configuration of settings is specific to each machine and does not transfer. By default, VS2013 will attempt to synchronize all settings if you are logged in with a Microsoft account.


Touring the VS2013 IDE

The user interface in VS2013's IDE has several differences from VS2012 and the previous versions of Visual Studio. Let's take a look at what is available in this recipe.

Getting ready

All you will need for this recipe is a copy of VS2013 so that you can follow along with where different options are located. The following screenshot provides an overview of what will be covered:

The legend for the highlighted items in the preceding screenshot is as follows:

  • The user's account entry/selection is indicated with 1

  • The notification center is indicated with 2

  • The Feedback menu is indicated with 3

  • The scrollbar thumbnail is indicated with 4

  • CodeLens (Ultimate only) is indicated with 5

  • The editor window controls are indicated with 6

How to do it…

Over the next few pages, we are going to take a firsthand look at the new areas of the Visual Studio IDE. You may follow along with your own project or use the sample project where indicated.


This screenshot shows the choices available when the Feedback menu is accessed by clicking on the chat balloon (far left icon):

Indicated by a chat balloon, the feedback icon provides an immediate way to send feedback to Microsoft from within VS2013. When the chat balloon is clicked, a drop-down list appears, allowing you to select from either Send a Smile (indicating a positive commentary) or Send a Frown (indicating negative commentary). Functionally, there is no difference in the dialog box that appears, but the choice of a smile or frown allows you to provide context for your remarks so that there is no ambiguity in your message. Each option allows you to include an e-mail address so Microsoft has a way to respond, and the frown option has an additional checkbox to indicate whether or not your comments are describing a bug.

The menu also provides the ability to report a bug and access the MSDN forums within Visual Studio. Both options provide a quick way to accomplish these tasks so that you make a report or seek help and get back to coding with minimal distractions.


Between the Feedback icon and the Quick Launch field is the flag icon representing notifications:

In the preceding screenshot, you can see that one update is pending. The notification flag is designed to provide an unobtrusive alert when updates to VS2013 and the installed packages are available. Notifications listed in the sidebar are color-coded with yellow and red, which are used to indicate medium and high priorities respectively. Examples of notifications that could appear include notices about updates to Visual Studio, updates to installed extensions or samples, or notices alerting that the trial period is ending. Notifications may be dismissed en masse, and once they are dismissed they do not reappear.

User account

If you have signed in to VS2013 with a Microsoft account (see the Synchronizing settings recipe), this area displays the graphical avatar along with your account's display name. The following screenshot shows the difference in the display that occurs when you log in:

It also provides a way to sign in if you have not done so, or if you wish to change the active account being used. In the preceding screenshot, the left-hand side has the text Sign in, and a grey icon indicates that the user has yet to login. On the right-hand side, you can see the difference when the user has logged in, as the username has replaced the Sign in text, and the gray icon has changed to reflect the user's avatar (which in this case is a green icon overlaid with the white initials of the user's name).

Scroll bar thumbnail

The scroll bar has expanded its usefulness in VS2013. You can now customize it to show your overall position in a source file, and provide a tool tip that lets you examine code elsewhere in your current file without changing your current location. The new option is called map mode, as opposed to the historical behavior that is called bar mode (which is the traditional scrollbar appearance and behavior). All aspects of the map mode are customizable, including whether it appears at all, its width (narrow, medium, or wide), and the ability to show the preview tool tip.

The following screenshot shows these features in action:

The preceding screenshot shows the scroll bar configured to be in map mode. The first arrow (marked as 1) indicates that what is being displayed in the editor is located relative to the overall source file. The second arrow (marked as 2) is pointing to the preview tool tip that appears when your mouse cursor hovers over the scroll bar.

The scroll bar's pull down feature remains. When it's used to split the main window, it allows for two independent viewing panes of the same file, and each can have their own independent vertical scroll bar. In the split view mode, both vertical scroll bars share the same options (width, bar mode versus map mode, and so on).

The following screenshot lists all of the options available for configuring the scroll bar's functionality. It can be accessed directly by right-clicking on the vertical scroll bar and selecting Scroll Bar Options…. Alternatively, it is accessible in VS2013's main Options dialog box by navigating to Tools | Options, with the scroll bar settings listed under Text Editor | All Languages | Scroll Bars. For additional customizations, you may set the language (C++, C#, and so on) settings for the scroll bar in the Options dialog box if desired:

Peek Definition

Visual Studio has had the Go To Definition (F12) option for several versions now. When we right-click on a method, or move the cursor to it, selecting the Go To Definition option will automatically bring you directly to the file with the corresponding definition. While you can easily navigate back and forth with (Ctrl + -) and (Ctrl + Shift + -), sometimes changing the open file is not what you would like to do. Enter Peek Definition (Alt + F12). This allows you to select a method and look it up, but instead of switching to the appropriate file, VS2013 will create a mini-window within your current editor. The following screenshot shows the results of using the Peek Definition option on the ConfigureAuth() method:

Sequential peeks can be performed, each opening via a tabbed interface. Navigation between these tabs (represented by circles) can be done via the mouse or keyboard: peek forward (Ctrl + Alt + =) and peek backward (Ctrl + Alt + -). The Peek Definition window uses the same scroll bar behavior as that of the parent editing window, and this behavior can be changed in either window by right-clicking on the scroll bar and selecting Scroll Bar Options....

CodeLens (Visual Studio Ultimate Only)

CodeLens, also known as code information indicators, is a feature specific to VS2013 Ultimate. Activated by default, CodeLens provides real-time meta-information about the file you open in your main editor window:

As illustrated in the preceding screenshot, shown inline with your code will be light colored term references, and the results of executed tests for each method/function as marked by the passing term. The references term indicates the number of places a method is used, and can also display a pop-up window on a mouse over that shows where it has been used. Likewise, the passing term relays the unit test results inline. While working with projects checked out from Team Foundation Server (TFS), CodeLens will also display the most recent author of the method in question. Clicking on that name will pop up a details window listing the change history.

If you would prefer to keep your hands on the keyboard, holding down Alt will bring up hotkeys that can be used to select among the features discussed earlier. The following screenshot illustrates these options, with Alt + 2 opening a pop-up dialog box listing references for the selected method and Alt + 3 listing details about unit tests. The display options for CodeLens are labelled as Code Information Indicators in the Options dialog box and can be found under Text Editor | All Languages | Code Information Indicators:

Code Maps (Visual Studio Ultimate Only)

VS2013 Ultimate continues the use of a code visualization tool that Microsoft calls Code Maps to provide a representation of the open project. The following screenshot shows Code Maps in action:

Code Maps can be created and used in VS2013 Ultimate, but VS2013 Premium and VS2013 Professional can only consume them. However, users of Premium and Professional can interact with the maps and add comments/flags as they are reviewed. Code Maps can be activated in an editor window via Ctrl + `, which is Ctrl plus the backquote key (typically found sharing a key with tilde). It can also be called by right-clicking in the editor window on a particular method or class that you want to map.

Once generated, the map may be manipulated in several ways, including zooming and the ability to expand to show related elements. Individual elements may be double-clicked so that they are brought up in the code editor for closer analysis. An element may also be right-clicked when in the Code Map for further navigation options (Go To Definition, Show Base Types, and so on) or to be commented on. This is particularly helpful for large or complex code bases where a map can assist in comprehension by visualizing the relationships and adding commentary external to the source code.

The Code Map indicates your position from the active editor window on the map with a green arrow icon. In the preceding example's screenshot, the editor is in the Vehicle class, which is pointed to on the Code Map by the green arrow.

See also


Project round-tripping

If you would like your .NET-based projects to be compatible with the previous versions of Visual Studio, be sure to choose a version of the .NET Framework that they support. For example, if you would like your project to support VS2010, be sure to target .NET 4.0, as .NET 4.5 is not compatible. Round-tripping is useful for situations where not all members of a development team have VS2013, as well as for situations when you wish to tread lightly on older projects.


As a friendly reminder, be sure that both versions of Visual Studio are up-to-date while sharing projects between VS2012 and VS2013. As noted in the While you were gone section of the Preface, this means Update 4 should be applied to VS2012.

In this recipe, we will discuss how projects can be shared across Visual Studio versions and a few details about how projects are handled.

Getting ready

The default .NET Framework in VS2013 is 4.5, so it is very easy to create a project that cannot open in VS2010. If you are not using any features specific to 4.5+, it is merely a matter of changing the project's properties to target 4.0. Keep in mind that some features will not be supported outright, but will be gracefully ignored.

Round-tripping is useful for a number of reasons. While supporting legacy projects, it is usually preferred to alter the existing code as little as possible. The support for older projects means that you can use VS2013 to edit them without keeping a copy of VS2012 installed. It also provides a way for users of VS2013 to work with fellow developers who are yet to upgrade from VS2012.

How to do it…

The best practice is to test upgrading on a backup of your legacy project. This way, you have an easy way to return to the status quo in the event of a failure or complication. Most projects will simply open without any complaint, especially those from VS2012 and, to a lesser extent, VS2010. If Visual Studio doesn't object, it is simply a manner of opening your old project in VS2013 and getting to work. Upon making edits and checking your code (if necessary), fellow developers running VS2010/VS2012 will have no difficulty making their own contributions.

How it works…

Visual Studio uses solution files to store details about the projects and solutions you create. Ending with the .sln extension, these files help Visual Studio manage your project. For example, a solution created in VS2012 has the following header at the beginning of its SLN file:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012 

By comparison, a solution created in VS2013 has this header as follows:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.20623.1 VSUPREVIEW
MinimumVisualStudioVersion = 10.0.40219.1


The initial blank line is intentional for both examples.

The third line (prefaced with #) indicates the "human-readable" version of Visual Studio used to create the project. VS2013 projects add two additional lines to this header as shown in the preceding code snippet. The fourth line shows VisualStudioVersion, which specifies the full build version of Visual Studio used, while the fifth line lists the value MinimumVisualStudioVersion, which indicates the minimum version of Visual Studio that can be used to open the project.


Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

There's more…

Not every project type supports round-tripping, as some require specific changes to be made in order to run under VS2013. Some notable project types and their exceptions are as follows.

Windows Store applications

Windows Store apps have some special requirements. Apps targeting Windows 8.1 require VS2013 and the underlying OS to be Windows 8.1. VS2013 can work with existing Windows 8 store apps if they were created by VS2012. As previously noted, Windows 8.1 will quickly replace Windows 8, so all new apps should target that platform.

The Model-View-Controller (MVC) framework

Visual Studio 2013 brings support for MVC 5 in addition to supporting MVC 4, while Visual Studio 2012 only supports MVC 3 and MVC 4. Visual Studio 2010 SP1 only supports MVC 2 and MVC 3. These limitations dictate whether or not your project will upgrade. However, there are tools and guidance on how to migrate your application to a newer version of MVC. Upgrading an MVC 2-based application to MVC 3 can be done with the standalone upgrade from CodePlex at Once this is completed, Microsoft provides guidance on upgrading the application from MVC 3 to MVC 4 at Unfortunately, the upgrade from MVC 3 to MVC 4 is a manual process.

MSI setup (.vdproj)

This project type refers to Visual Studio Installer projects, which are not supported in VS2013.

Upgrading an existing project

Depending on the nature of the solution or project you are working on, Visual Studio may require you to convert your project. You will be prompted to make a conversion decision, as shown in the following screenshot:


If you decide not to upgrade the project, you may do so later via Project | Upgrade Solution. As you may expect, the best practice is to perform a trial conversion on a copy of your solution in the event of something going wrong.

Creating a new project

Starting a new project in VS2013 remains unchanged from previous versions, but some of the available choices have changed. If you have not previously updated VS2012, one of the changes to notice is that VS2013 offers .NET Framework 4.5.1 as a framework that can be targeted. Some other new choices include templates to create apps for SharePoint and Office, as well as Python-based projects. See the Project round-tripping recipe for important considerations while creating projects that are destined to be edited in different editions of Visual Studio.


Managing the editor windows

One of the advantages of using a graphical IDE is the ability to have multiple windows open, and learning how to customize their size and layout in Visual Studio is important for maximizing their productivity. Given the multitude of windows (editors, debugger output, and so on) Visual Studio has open, it can be helpful to learn how to place them where you want so that you can focus on your work without being slowed down by clutter.

Tab pinning allows you to mark individual windows so they stay open while you navigate through the editor. Previewing documents is a useful way to navigate across several files without cluttering your tabs with several open documents. This recipe will explore both options.

Getting ready

Open either the VS2010_Web sample solution or use a solution of your choice. Ensure that the Solution Explorer window is open.

How to do it...

The following steps will show how the position of open windows can be positioned to your liking. Let's get started:

  1. In the Solution Explorer window, locate the Default.aspx.cs file in the VS2010_Web project and double-click on it. The source file will open in the main window area as in the previous versions of Visual Studio. However, you will now notice that the document tab features a pin icon next to the tab name, as you can see in the following screenshot. You'll use that pin in just a few steps:

  2. Using the Solution Explorer window, open both the About.aspx.cs and Global.asax.cs files by double-clicking on them. You should now have three documents open with their tabs showing in the tab well (this refers to the row of tabs for each open document in the editor), as shown in the following screenshot:

  3. Click on the Default.aspx.cs tab to select it and then click on the pin. The pin will change to point downwards indicating that the document is now pinned. Visual Studio 2013 will always keep pinned tabs visible in the tab well. These pinned tabs will remain visible even when Visual Studio needs to start hiding unpinned tabs to save screen display space. The pinned document tab will be moved to the left next to any other pinned documents you may have open, as shown in the following screenshot:

  4. Right-click on the Global.asax.cs document tab and click on the Close All But This option to close all open documents except for the one currently selected. This will include closing any pinned documents, which are shown in the following screenshot:


    There is a related option: Close All But Pinned. This is useful when you would like to only keep pinned files open.

  5. Reopen both the Default.aspx.cs and About.aspx.cs files that you closed by double-clicking on them in Solution Explorer.

  6. One of the usability problems with document tabs in Visual Studio 2010 was that you could accidentally float documents by double-clicking on a document tab.

  7. In Visual Studio 2013, this behavior has changed. Double-click on a document tab of your choice and notice how Visual Studio sets the focus to this tab instead of floating it. (This is the same behavior as single-clicking on a document tab.)

  8. Press Ctrl + Shift + F to open the Find in Files dialog box. Enter the class in the Find what field and ensure Look in is set to Solution, then click on the Find All button.

  9. In the Find Results 1 window, select a result from the ChangePassword.aspx file.

  10. The file will open in the preview tab, located on the right-hand side of the tab well.

  11. The preview tab shows the contents of the currently selected document if it is not already open. In the Find Results 1 window, select a result from the Login.aspx file. It will now be opened automatically in the preview tab, and the ChangePassword.aspx document will be closed.

  12. Assume you now want to keep the Login.aspx file open for a while. Either click on the Keep Open icon on the tab or change the contents of the file. Any document in the preview tab that is changed is automatically promoted to a normal tab.

Visual Studio will move the document from the preview tab area into the main tab area. The color of the tab will also be changed from purple to blue indicating that the tab is now a normal document tab.

How it works...

Pinning documents works much like pinning does in any other part of Visual Studio, and is very handy for keeping the documents that you are working on regularly within easy reach, especially when you have many documents open at once.

The preview document tab is a great way to prevent tab clutter and becomes very useful while debugging deeply nested code. You may recall that Go To Definition as one function that uses the preview document tab. For example, multiple source files may be opened as you trace a program's operation across methods and classes. The preview document tab helps you cycle quickly through these files while preventing the tab well from filling up with documents that aren't needed for more than a few moments.

There's more...

As always, there are ways to customize the behavior of the document tabs in Visual Studio.

Single-click preview in Solution Explorer

The preview tab isn't restricted to just the Find Results window. It can also be used from within the Solution Explorer. If you activate the Preview Selected Items button in the Solution Explorer toolbar, then every item you click on will automatically be opened in the preview tab. The Preview Selected Items button is a toggle button (shown in the following screenshot). If you want to disable the behavior, you only need to click on the button to deselect it and the preview behavior will be turned off:

Customizing tab and window behavior

Navigating to Tools | Options in Visual Studio will show the following dialog box:

There are a number of options here that let you control how the tabs behave. With Visual Studio 2010 Productivity Power Tools, many developers found different ways to configure their tab well to get the experience they wanted, and while not everything from the power tools came across to the final Visual Studio 2012 product, a number of features most certainly did. Feel free to experiment with the Tabs and Windows settings to get Visual Studio working the way you like it most.


Finding Visual Studio commands

The goal of the Quick Launch box is to provide a keyboard-friendly way of accessing the extended features of Visual Studio without needing to clutter the central interface. Keyboard shortcuts are a great way to speed up tasks, but it can be difficult to learn and remember while first starting out, or while exploring a new area of Visual Studio. The Quick Launch option addresses this by providing a way to locate different areas of the program, learn keyboard shortcuts, and provide a keyboard-centric way to access commands.

Getting ready

Simply start Visual Studio 2013.

How to do it…

To try it out, start by pressing Ctrl + Q, then begin typing the topic/subject that you are looking for, as shown in the following screenshot:

What is important to notice is that Quick Launch can do even more than what may be obvious at first glance. In this example, notice that open was the term entered as a search term. Quick Launch produces a list of results to this query, grouped by the following categories: Menus, Options, and NuGet Packages. As you can see, this list of results is more than just commands, it also includes various areas in the Options dialog as well as NuGet Packages.

You can immediately navigate through the search results with the arrow keys on the keyboard if the desired result is immediately available. You can access a command directly from this list, and where available, the accompanying keyboard hotkey for a command will be listed. In this way, you can learn new shortcuts while doing your daily work.

In the next example, jquery was entered into Quick Launch, producing a list of results that includes context-specific File menu commands (Save and Save As), the option to switch to an open editor window with jquery in the file name (jquery.ui.autocomplete.min.css), or to search NuGet for packages using jquery as the search term.

The following screenshot is showing the availability of these various options:

There's more…

The Quick Launch option can go further. Let's return to the results of the open term. Note that at the bottom, the Quick Launch option indicates that Ctrl + Q can index through additional views. Additional presses of Ctrl + Q will toggle the list of results to show only results from an individual category, in this case Menus, Options, or NuGet Packages. A final press of Ctrl + Q will return to displaying all of the available results. The ability to toggle through categories is particularly useful when your Quick Launch list is lengthy and you would like to ignore unnecessary categories that are cluttering the list of results. Pressing Esc once will clear the search results in Quick Launch, and pressing Esc again will return you to the open file in your editor.


Using the Command Window / Command Aliases

The Command Window (accessible via Ctrl +Alt +A and available on premium editions of VS2013) allows you to keep your hands on the keyboard while quickly accessing commands via an integrated command prompt window. As Microsoft ships Visual Studio preloaded with command definitions, entering an alias will display all of the currently defined commands, and the alias cmd action (where cmd is the desired name of your alias and action defines what should happen) will allow you to define your own. You can see from the following screenshot that typing bl is much faster than typing Debug.Breakpoints. Note that by default, command aliases are stored as part of your synchronized profile:


Searching and navigating

Visual Studio provides many ways to make maneuvering through your code easier and more efficient.

Getting ready

To best see this in action, open a project that has multiple files available for editing. This can be the sample project or one of your own choice. Once it is open, simply open a couple of source files.

How to do it…

Pressing Ctrl + Tab provides easy access to a couple of different ways to navigate around Visual Studio. If Ctrl + Tab is pressed and immediately released, Visual Studio will alternate between the two most recent files that you have opened in the editor window. This provides a quick way to move back and forth. If Ctrl + Tab is pressed and Tab is released, a pop-up window will appear. Continue to hold down Ctrl when it appears, and then arrow keys can be used to maneuver around the list of all active files and windows. To make a selection, either release Ctrl while highlighting the desired target, or while holding Ctrl, press Enter. This is shown in the following example's screenshot, where active files currently open in Visual Studio are shown in the right-hand side column, while open tool windows are shown in the left-hand side column:

There's more…

If you would rather take a hybrid (mouse + keyboard) approach, the window Ctrl + Tab produces also supports selection by mouse. Start in the same manner as done earlier in this recipe, holding down Ctrl + Tab to bring up the window. Release Tab while holding down the Ctrl key and then use your mouse to left-click directly on the file you would like to switch to.

Quickly searching your code

Searching a project file to find specific strings of text is a common daily task performed by developers. Visual Studio tries to make this easy by offering specific tools to find and replace text at various levels of your code base. Several options are available under Edit | Find and Replace, including Quick Find, Quick Replace, Find In Files, and Replace In Files.


The Incremental Search option (Ctrl + I) is a quick way to search within the file you are currently editing. When activated, a Find dialog box appears in your active editor window, allowing you to enter search terms.

The Quick Find (Ctrl + F) and Quick Replace (Ctrl + H) options share a common dialog box. Both provide the ability to search the current code block, the current project, all open documents, or the entire solution. If your search options include the file that's currently open, the vertical scroll bar will highlight any matches found. This provides quick visual feedback on the frequency of a search item:

Another feature that Quick Find and Quick Replace share is the ability to set the following search options: match case, match whole word, and whether or not regular expressions can be used. The use of regular expressions allows for more complex queries to be used, allowing users to extract more detailed information from their searches.

The Find In Files (Ctrl + Shift + F) and Replace In Files (Ctrl + Shift + H) options provide a more advanced method of conducting searches across a code base. They expand on the functionality offered by the quick tools by allowing you to specify certain file types that should be searched (for example, all HTML and JavaScript files) and provide the ability to display the results of an operation in a separate window.

In the preceding example's screenshot, a simple regular expression was used to search the entire solution using the specified file mask. The results were outputted to Find Results 1, which is a live window. This means that you can click on a line with a particular search result and you will go directly to that file where the match was made.


Navigating in depth

The Solution Explorer window that we were accustomed to in Visual Studio 2010 was good for being able to understand how files were organized into the various projects of a solution, but it didn't do much more than that. With Visual Studio 2013, Microsoft has revisited Solution Explorer and given it an overhaul. It still contains all of the functionalities you know from the old Solution Explorer, and it adds to that a range of new features intended to make navigating and searching within your solution a more powerful yet simpler experience.

Getting ready

Open the same VS2010_Web solution that we have been using for the other recipes in this chapter or choose a solution of your own.

How to do it...

  1. We'll begin by navigating through our solution. Locate the Default.aspx page in the VS2010_Web project and click on the arrow next to it so that its contents are displayed. As you would expect, there is a code-behind file and a designer file:

  2. Look at the Default.aspx.cs file. You can see that there is a small arrow next to it just as there was for the Default.aspx page. Click on the arrow:

  3. Visual Studio 2013 expands the file to show its contents, and in the case of a code-behind file, these contents are the class definitions it contains. Classes have methods and properties in them, so click on the arrow next to the _Default class to see the methods inside it. Since the VS2010_Web project is just a shell, there is only an empty Page_Load() method, as shown in the following screenshot:

  4. Now select the IService1.cs file from the VS2010_Web.Services project and expand it to see its contents. You will see that there is both an interface definition in this file (IService1) and a class definition (CompositeType), as shown in the following screenshot:

  5. Right-click on the IService1 interface and click on the Derived Types option to see what classes implement this interface:

  6. The Solution Explorer window will change views to show you the types that either implement this interface or inherit from it, as shown in the following screenshot. Click on the back button (showing the blue background) to return to the standard Solution Explorer view:

  7. Right-click on the IService1 interface and choose the Is Used By option to see where the interface is currently being used. As with the Derived Types option, you will see Solution Explorer change its context to only show the interface and where that interface is used in the solution, including line and column numbers:

  8. Return to the regular Solution Explorer view by clicking on the home button, shown in the following screenshot:

  9. At this point, you know how to navigate using Solution Explorer, and you have already used the existing Navigate To feature in the Finding Visual Studio commands recipe while opening a file. With the enhancements to Solution Explorer, you can locate files in much the same way as with the Navigate To command, albeit with a slightly different user experience. Click on the Search Solution Explorer textbox at the top of the Solution Explorer window, or use the default shortcut key of Ctrl + ; (Ctrl + semicolon).

  10. Enter serv in the textbox and wait a moment for the search results to display. The results should look similar to the following screenshot. You can not only see the filenames that match the search term but also any matching references, classes, and methods:

How it works...

The Navigate To feature from Visual Studio 2010 was a fantastic addition to Visual Studio. It had problems in large projects with many search matches as the location of a match was embedded in the result itself, making it hard to locate the specific match you were after. The new Solution Explorer search tool provides similar results to the Navigate To feature, but having the location of a match represented in the tree view makes it very easy to quickly identify the specific match you are interested in.

There's more...

It's worth mentioning a few other things about searching within your solution.

Navigation behavior

Assuming you have the Preview Tab enabled for Solution Explorer, as you navigate using Solution Explorer to various classes and methods, you may have noticed that the document preview tab was updating and showing exactly where the selected class, method, or property was declared. This makes it easy to see what the code is doing without the need to specifically open the file or scroll through a source file to see what code is actually inside a method, class, or property.

CSS, HTML, and JavaScript files

Even though it's possible to extract the structure from CSS, HTML, and JavaScript files, Solution Explorer doesn't show the internal structure of these files. You can navigate to the source file, but not to any of its contents.

About the Authors

  • Jeff Martin

    Jeff Martin has been a contributing writer for InfoQ ( for over four years, focusing on .NET and Microsoft-based platforms. Experienced in writing, testing, and designing software, he enjoys learning about new technologies and explaining them to a broader audience. You can follow his work at InfoQ as .NET lead editor.

    Browse publications by this author
  • Richard Banks

    Richard Banks has developed software for the last 20 years for a wide range of industries and development platforms. Over the years he has played many roles including that of a developer, team lead, project manager, and CIO/CTO. He is a Professional Scrum Trainer, runs the Sydney ALT.NET user group and the Talking Shop Down Under podcast. He owns and contributes to a few open source projects, and has spoken at Microsoft TechEd and a number of other events and user groups around Australia. For some strange reason, he gets a real kick out of helping development teams to improve and produce great software. If you want to get in touch, he tweets at @rbanks54 and blogs at He currently works as a Principal Consultant for Readify and is a Microsoft Visual Studio ALM MVP.

    Browse publications by this author

Latest Reviews

(2 reviews total)
初心者として、不適だと思う、その内容は経験がある開発者にて、 いいツールだと思う
Very knowledgeable, great presentation. Please, give an estimation for a delivery date when an order is processed.
Book Title
Access this book, plus 8,000 other titles for FREE
Access now