Book Image

Visual Studio 2015 Cookbook - Second Edition

By : Jeff Martin
Book Image

Visual Studio 2015 Cookbook - Second Edition

By: Jeff Martin

Overview of this book

Visual Studio 2015 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 2015 is packed with improvements that increase productivity, and this book walks you through each one in succession to help you smooth your workflow and get more accomplished. From customization and the interface to code snippets and debugging, the Visual Studio upgrade expands your options — and this book is your fast-track guide to getting on board quickly. Visual Studio 2015 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 VS2015 offers, but what it takes to put it to work for your projects.
Table of Contents (17 chapters)
Visual Studio 2015 Cookbook Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Touring the VS2015 IDE


It is a great idea to familiarize yourself with the main components of the VS2015 IDE, since that is where you will spend most of your time. Users coming from VS2013 will see many similarities, but there some new details that you will find useful to review. 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 VS2015 so that you can follow the location of the different options. The next 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 by 1

  • The notification center is indicated by 2

  • The Send Feedback menu is indicated by 3

  • The scrollbar thumbnail is indicated by 4

  • CodeLens (Professional and Enterprise editions only) is indicated by 5

  • The editor window controls are indicated by 6

  • Git version control indicators (for Git-based projects; not available on Community) are represented by 7

How to do it…

Over the next few pages, we will take a first-hand look at how these areas of the Visual Studio IDE can be used. You may follow along with your own project, or just create a new project using one of the templates provided with VS2015.

Send Feedback

This screenshot shows the choices available when the Send Feedback menu is accessed by clicking on the Send Feedback icon (represented by a person with a chat balloon):

The menu shown in the preceding screenshot provides an immediate way to send feedback to Microsoft from within VS2015. From this menu, you can choose from the following actions:

  • Report a Problem...: Provides Microsoft with information about a bug you have experienced. (See the next screenshot for this dialog box.)

  • Provide a Suggestion...: Uses your current web browser to navigate to the VS2015 area on Microsoft's UserVoice site to request a new feature or change to V2015.

  • Rate This Product...: Uses your current web browser to navigate to a web-based product survey for VS2015.

  • Settings...: Allows you to view and change whether or not you will send information to Microsoft as part of the Visual Studio Experience Improvement Program.

Notifications

On the far left of the Quick Launch field is a flag icon that indicates product notifications (if any):

In the preceding screenshot, you can see that three updates are pending. The notification flag is designed to provide an unobtrusive alert when updates are available to VS2015 and its installed packages. Notifications listed in the sidebar are color-coded with yellow and red, which are used to indicate medium and high priority respectively.

Examples of notifications that could appear include the presence of Visual Studio updates, updates to installed extensions or samples, or notice indicating that the VS2015 product license is invalid. Notifications may be dismissed en masse, and once dismissed, they do not reappear:

Tip

If you would like to review dismissed Notifications, navigate to Tools | Extensions and Updates. Select Updates and review the Product Updates that are available, as shown in the preceding screenshot.

User account

If you have already signed in to VS2015 with a Microsoft account (refer to 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:

The Sign in command 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 log in. On the right-hand side, you can see the difference after the user has logged in, as the user's name and avatar has replaced the Sign in text.

Scroll bar thumbnail

Similar to other code editors that you may be familiar with, VS2015 has a configurable scroll bar in its main editor window. It can be customized 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, which is called bar mode (which follows the traditional scrollbar appearance and behavior). All aspects of 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 2) indicates what is being displayed in the editor relative to the overall source file. The second arrow (marked as 3) points to the preview tool tip that appears when your mouse cursor hovers over the scroll bar.

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

The following screenshot lists all 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 the main Options dialog box of VS2015 by navigating to Tools | Options with the scroll bar settings listed under Text Editor | All Languages | Scroll Bars. For additional customizations, you may set language-specific settings (C/C++, C#, and so on) 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, VS2015 will create a mini window within your current editor. The following screenshot shows the results of using the Peek Definition option on the PasswordSignInAsync() method:

Sequential peeks can be performed, each opening via a tabbed interface. Navigation between these tabs (represented by circles / marked by the arrow in the preceding screenshot) 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 Professional and Enterprise only)

CodeLens, also known as code information indicators, debuted in VS2013 but was limited to the Ultimate edition. In response to user feedback, Microsoft has made it available to both VS2015 Professional and Enterprise. 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 in line with your code will be light-colored term references, and the name of the developer with the time since the most recent commit. The references term indicates the number of places a method is used, and can also display a pop-up window upon hovering the mouse over the term that shows where it has been used. If unit testing is part of the project, the number of passing and failing tests can be shown.

VS2015 provides additional functionality using either the source control provided by Team Foundation Server (TFS) or Git. This enables CodeLens to display the most recent author of the method in question, and 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 + 5 displaying information about who last modified the code. Alt + 7 provides the revision history:

New in VS2015 is the addition of file-level indicators for supported file types. When Visual Studio isn't able to offer details at the code element level, file-level indicators provide similar (although, not identical) functionality. A file-level indicator is shown at the bottom of the editor window when available, as indicated by the arrow in the following screenshot:

Tip

CodeLens provides code element-level indicators for C# and Visual Basic files. All other source file types receive file-level indicators.

The display options for CodeLens are labeled as Code Information Indicators in the Options dialog box, and can be found under Text Editor | All Languages | Code Information Indicators. Alternatively, you may simply right-click on the indicator line, and choose the CodeLens options:

Code Maps (Visual Studio Enterprise only)

VS2015 Enterprise provides the ability to generate and use a code visualization tool, which 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 VS2015 Enterprise, but VS2015 Professional and VS2015 Community can only consume them. This means that users of Professional and Community 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 back quote key (typically found sharing a key with tilde). It may be also 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 on the map from the active editor window 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 chevron (relationship marked in the preceding screenshot).

See also

  • Refer to the Choosing the right version of Visual Studio 2015 section in the Preface