© Dirk Strauss 2020
D. StraussGetting Started with Visual Studio 2019https://doi.org/10.1007/978-1-4842-5449-3_1

1. Getting to Know Visual Studio 2019

Dirk Strauss1 
(1)
Uitenhage, South Africa
 

Visual Studio is an amazing bit of software. If you have been using Visual Studio for a number of years, you will certainly agree that the IDE offers developers a host of tools and features to make them more productive. You will also be aware that it has grown a lot during the past couple of years and is an absolute powerhouse when it comes to providing tools to develop world-class software.

Initially released as Visual Studio 97 in February 1997, this was the first attempt at using a single development environment for multiple languages. The evolution of Visual Studio is detailed in Table 1-1.
Table 1-1

The evolution of Visual Studio

Release

Version

.NET Framework

Release Date

Visual Studio 2019

16.0

3.5–4.8

April 2, 2019

Visual Studio 2017

15.0

3.5–4.7

March 7, 2017

Visual Studio 2015

14.0

2.0–4.6

July 20, 2015

Visual Studio 2013

12.0

2.0–4.5.2

October 17, 2013

Visual Studio 2012

11.0

2.0–4.5.2

September 12,  2012

Visual Studio 2010

10.0

2.0–4.0

April 12,  2010

Visual Studio 2008

9.0

2.0, 3.0, 3.5

November 19, 2007

Visual Studio 2005

8.0

2.0, 3.0

November 7, 2005

Visual Studio .NET 2003

7.1

1.1

April 24, 2003

Visual Studio .NET 2002

7.0

1.0

February 13, 2002

Visual Studio 6.0

6.0

N/A

June 1998

Visual Studio 97

5.0

N/A

February 1997

There is so much to see and learn when it comes to Visual Studio. Therefore, in this chapter, we will start by having a look at the following:
  • Installing Visual Studio

  • What workloads are

  • Exploring the IDE (integrated development environment)

  • Existing and new features available in Visual Studio 2019

  • Productivity tips

If you are using a macOS or a Windows machine, Visual Studio will happily run on both. Let us see where to find the Visual Studio Installer and get going.

Installing Visual Studio

At the time of this writing, Visual Studio 2019 is available for Windows machines as well as for macOS machines. You can download Visual Studio 2019 for Windows from https://visualstudio.microsoft.com/vs/, and if you are on macOS, you will need to head on over to https://visualstudio.microsoft.com/vs/mac/ to download the installer.

Clicking the Download Visual Studio button, you will see a list drop-down with the options as displayed in Figure 1-1.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig1_HTML.jpg
Figure 1-1

Versions of Visual Studio available

If you would like to compare the Visual Studio 2019 versions, you can have a look at https://visualstudio.microsoft.com/vs/compare/ for a detailed comparison. The bottom line is that if you want Visual Studio 2019 for free, download Visual Studio Community 2019.

Visual Studio Community 2019 is aimed at students, open source, and individual developers. The paid tiers include Visual Studio Professional 2019 which is aimed toward small teams and Visual Studio Enterprise 2019 aimed at large development teams.

Microsoft specifies enterprise organizations as those having more than 250 PCs or more than $1 million US dollars in annual revenue.

Let us have a brief look at the recommended system requirements for installing Visual Studio on your machine. For a comprehensive list, browse to https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements and have a read through that.

Visual Studio 2019 System Requirements

The system requirements for installing Visual Studio 2019 might differ from those of previous versions of Visual Studio. Refer to the documentation on https://docs.microsoft.com to review the system requirements for previous versions of Visual Studio.

Visual Studio Enterprise 2019, Visual Studio Professional 2019, Visual Studio Community 2019, and Visual Studio Team Foundation Server Office Integration 2019 all support the following minimum system requirements.

Operating Systems

The following Windows operating systems (64-bit recommended) are supported:
  • Windows 10 version 1703 or higher

  • Windows Server 2019 – Standard and Datacenter

  • Windows Server 2016 – Standard and Datacenter

  • Windows 8.1 with update 2919355

  • Windows Server 2012 R2 with update 2919355

  • Windows 7 SP1 with latest Windows updates

Hardware

There is obviously a line here that developers generally don’t like to cross when it comes to the minimum hardware specs. Many developers I know will geek out on system RAM and favor SSDs over HDDs. Nevertheless, here are the minimum recommended requirements:
  • 1.8 GHz or faster processor (quad-core or better recommended).

  • 2 GB of RAM (8 GB of RAM recommended).

  • 2.5 GB of RAM minimum if running on a Virtual Machine.

  • Between 800 MB and 210 GB of available hard disk space (depending on installed features, 20–50 GB of free space is typically required).

  • For improved performance, install Windows and Visual Studio on an SSD.

  • Minimum display resolution of 720p (1280x720) but works best at WXGA (1366x768) or higher.

Supported Languages

Visual Studio and the Visual Studio Installer is available in 14 languages as follows:
  • English

  • Chinese (Simplified)

  • Chinese (Traditional)

  • Czech

  • French

  • German

  • Italian

  • Japanese

  • Korean

  • Polish

  • Portuguese (Brazil)

  • Russian

  • Spanish

  • Turkish

Additional Notes

There are several additional requirements to take note of that I will briefly list here. There are however other requirements that might be of importance to your unique development environment. For a full list, refer to the system requirements at the following link: https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements
  • Administrator rights are required to install Visual Studio.

  • .NET Framework 4.5 is required to run the Visual Studio Installer and install Visual Studio.

  • Visual Studio requires .NET Framework 4.7.2 and is installed during setup.

Using Workloads

After Visual Studio has been installed, you can customize the installation by selecting feature sets, also known as workloads. Think of workloads as a collection of individual features that belong together. This allows you to easily modify Visual Studio to include only what you need.

To launch the workloads screen, find the Visual Studio Installer as can be seen in Figure 1-2.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig2_HTML.jpg
Figure 1-2

Find the Visual Studio Installer

Clicking the Visual Studio Installer will launch the installer from where you can modify your installation of Visual Studio as seen in Figure 1-3.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig3_HTML.jpg
Figure 1-3

Installing additional workloads

If you want to start doing Python development, you can simply check the Python development workload and install that. As can be seen in Figure 1-4, this will update the installation details section and show you exactly what is being installed and how much additional space you will need to install the selected workload.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig4_HTML.jpg
Figure 1-4

Workload installation details

The workloads also contain tabs, namely, Workloads, Individual components, Language packs, and Installation locations. If you needed to install an additional component such as Service Fabric Tools, you can do so by selecting the component on the Individual components tab.

When you have checked all the workloads and individual components you would like to install, you can choose to do the installation while downloading or to download everything before installing as can be seen in Figure 1-5.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig5_HTML.jpg
Figure 1-5

Installation options

This will modify your existing installation of Visual Studio 2019 and apply the changes you selected.

Exploring the IDE

The Visual Studio IDE is full of features and tools that help developers do what they need to do, efficiently and productively. Developers start off creating one or more projects that contain the logic for their code. These projects are contained in what we call a solution. Let’s have a look at the Solution Explorer first.

The Solution Explorer

In Visual Studio, the notion of solutions and projects is used. A solution contains one or more projects. Each project contains code that runs the logic you need in order for your application to do what it does.

Consider the example of a Shipment Locator application as can be seen in Figure 1-6.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig6_HTML.jpg
Figure 1-6

The Shipment Locator Solution

It is to this solution that you will add all the required projects in order to create your application. From the example in Figure 1-6, we can see that the solution contains three projects. The projects are as follows:
  • ShipmentLocator – WinForms application – C#

  • ShipMethodLogic – Class Library – C#

  • Tracking – Class Library – VB.NET

Of particular interest, you will notice that you can have a solution that contains a mix of C# projects and VB.NET projects. You are therefore not limited by a particular language and can create applications containing a mix of .NET languages.

The reason that we can mix .NET languages in the same solution is due to something we call IL (Intermediate Language). IL is used by the .NET Framework to create machine-independent code from the source code used in your projects.

The WinForms application will contain the UI needed to track and trace shipments. In order for the WinForms application to be able to use the logic contained in the other two class libraries, we need to add what is called a reference to the other projects.

This is done by right-clicking the project that you want to add the reference to and selecting Add Reference from the context menu (Figure 1-7).
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig7_HTML.jpg
Figure 1-7

Adding a project reference

When you click the Add Reference menu item, you will be presented with the Reference Manager screen as seen in Figure 1-8.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig8_HTML.jpg
Figure 1-8

The Reference Manager screen

Under the Projects tab, you will find the other two Class Library projects in your solution. By checking each one and clicking the OK button, you will add a reference to the code in these projects.

If you had to expand the References section under the ShipmentLocator project, you will see that there are two references to our Class Library projects ShipMethodLogic and Tracking as can be seen in Figure 1-9.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig9_HTML.jpg
Figure 1-9

Added references

This will now make all the code you write in the ShipMethodLogic and Tracking projects, available to the ShipmentLocator project. Having a look at the toolbar on the Solution Explorer (Figure 1-10), you will notice that it contains several buttons.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig10_HTML.jpg
Figure 1-10

The Solution Explorer toolbar

The buttons contained here are displayed as needed. The View Code button, for example, will only show up in the toolbar when a file containing code is selected in the Solution Explorer. These buttons give you quick access to the following features as outlined in the following:
  1. 1.

    Preview Selected Items

     
  2. 2.

    Properties

     
  3. 3.

    View Code

     
  4. 4.

    Show All Files

     
  5. 5.

    Collapse All

     
  6. 6.

    Pending Changes Filter

     
  7. 7.

    Toggle between Solution and Folder views

     

I will not go through each one in detail, but of particular interest, you will notice that the Show All Files will display unnecessary files and folders such as the bin folder in your Solution Explorer. Go ahead and click the Show All Files button, and look at the Solution Explorer again.

By looking at Figure 1-11, you can see that it now displays the bin folder and the obj folder. These folders are not necessary for your code but are important to your solution.

The obj folder contains bits of files that will be combined to produce the final executable. The bin folder contains the binary files that are the executable code for the application you are writing.

Each obj and bin folder will contain a Debug and Release folder that simply matches the currently selected build configuration of your project.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig11_HTML.jpg
Figure 1-11

Solution Explorer displaying all files

You can now right-click the bin folder as seen in Figure 1-12 and click the Open Folder in File Explorer menu to quickly have a look at the contents of the folder.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig12_HTML.jpg
Figure 1-12

Open Folder in File Explorer

This is a nice shortcut for anyone needing to navigate to the location of the Visual Studio files in the solution.

If you open the bin folder and click the Debug folder contained in the bin folder, you will see the main exe as well as any referenced dll files in the project (Figure 1-13).
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig13_HTML.jpg
Figure 1-13

The contents of the Debug folder

These files will be updated each time you build or run your project. If this folder is blank, perform a build of your solution by pressing F6 or by right-clicking the solution and clicking Build Solution from the context menu as seen in Figure 1-14.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig14_HTML.jpg
Figure 1-14

Right-click solution options

You might be wondering what the difference between Build Solution, Rebuild Solution, and Clean Solution is? The differences are as follows:
  • Build Solution will do an incremental build of the solution of anything that has changed since the last build.

  • Rebuild Solution will clean the solution and then rebuild the solution from scratch.

  • Clean Solution will only clean the solution by removing any build artifacts left over by the previous builds.

If you are receiving funny build errors that do not seem to be errors in your code editor, try cleaning your solution and building it again.

Toolbox

When dealing with a UI file such as a web application or a WinForm application, you will notice that you have a Toolbox at your disposal (Figure 1-15).
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig15_HTML.jpg
Figure 1-15

The WinForms Toolbox in Visual Studio

The Toolbox allows you to add controls to your application such as text boxes, buttons, drop-down lists, and so on. This allows developers to design the UI of the application by dragging and dropping the relevant controls on the design surface.

You can also open the Toolbox by clicking the View menu and selecting the Toolbox menu item. It is worth noting that for some project types, you will not see any items in the Toolbox.

If you do not like the default layout of the Toolbox, you can right-click the tab or on an individual item in the Toolbox and perform one of several actions from the context menu as seen in Figure 1-16.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig16_HTML.jpg
Figure 1-16

Toolbox context menu

The context menu allows you to do the following:
  • Rename an item

  • Choose additional items

  • Remove items

  • Move items up and down

  • Sort items

  • Add a new tab

If you have third-party controls installed such as DevExpress or Telerik, you will find the controls specific to the installed components under their own tab in the Toolbox.

The Code Editor

Let’s add some basic UI components to our WinForm application as seen in Figure 1-17. To this code-behind, we will add some code to our project, just to get the ball rolling. All that this application will do is take a given waybill number and return some location data for it.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig17_HTML.jpg
Figure 1-17

The application design

The location data will be hard-coded in a Location class that was added to the project.

After adding the UI elements to the designer, swing over to the code window for the main WinForm application called Form1.cs. Add the following code in Listing 1-1 to the code-behind.

You will notice after adding the code that Visual Studio starts to underline some of the added code as seen in Figure 1-18. This is because Visual Studio is making suggestions to improve the quality of your code.
private void BtnTrack_Click(object sender, EventArgs e)
{
    if (!(string.IsNullOrWhiteSpace(txtWaybill.Text)))
    {
        string waybillNum = txtWaybill.Text;
        if (WaybillValid())
        {
            Package package = new Package(waybillNum);
            Location packLoc = package.TrackPackage();
            if (packLoc != null)
            {
                txtLocationDetails.Text = $"Package location: " +
                    $"{packLoc.LocationName} with coordinates " +
                    $"Long: {packLoc.Long} and " +
                    $"Lat: {packLoc.Lat}";
            }
        }
        else
            MessageBox.Show("You have entered an invalid Waybill number");
    }
}
private bool WaybillValid()
{
    return txtWaybill.Text.ToLower().Contains("acme-");
}
Listing 1-1

The Code-Behind Form1.cs

The underlined code is code that Visual Studio is making suggestions for improvement on.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig18_HTML.jpg
Figure 1-18

Visual Studio code improvement suggestions

To view the details of the suggestion, hover your mouse over one of the underlined lines of code. Visual Studio will now display the details of the suggested change as seen in Figure 1-19.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig19_HTML.jpg
Figure 1-19

Code change suggestion

Here we can see that Visual Studio is suggesting the use of the var keyword. At the bottom of the code editor, you will also see that Visual Studio displays the count of errors and warnings as seen in Figure 1-20.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig20_HTML.jpg
Figure 1-20

Errors and warnings

You are able to navigate between the warnings and errors by clicking the left and right arrows. You can also perform a code cleanup by clicking the little brush icon or by holding down Ctrl+K, Ctrl+E.

After cleaning up the code and adding the code suggestions that Visual Studio suggested, the code looks somewhat different as can be seen in Figure 1-21.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig21_HTML.jpg
Figure 1-21

Code suggestions applied

With all the code suggestions applied, Visual Studio displays a clean bill of health in the status indicator at the bottom of the code editor.

Navigating Code

Visual Studio provides several features allowing developers to navigate code throughout the solution. Knowing how to use these navigation features will save you a lot of time.

Navigate Forward and Backward Commands

If you look at the toolbar in Visual Studio, you will see the Navigate Forward (Ctrl+Shift+-) and Navigate Backward (Ctrl+-) buttons. These allow developers to return to the last 20 locations that the developer was at.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig22_HTML.jpg
Figure 1-22

Navigate forward and backward

You can also find these commands from the View menu under Navigate Backward and Navigate Forward.

Navigation Bar

The navigation bar in Visual Studio as seen in Figure 1-23 provides drop-down boxes that allow you to navigate the code in the code base. You can choose a type or member to jump directly to it in the code editor.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig23_HTML.jpg
Figure 1-23

Visual Studio navigation bar

It is useful to take note that members defined outside the current code file will be displayed but will be disabled and appear gray. You can cycle through the drop-down boxes in the navigation bar by pressing the tab key.

Each drop-down also has its own individual function. The left drop-down will allow you to navigate to another project that the current file belongs to. To change the focus to another class or type, use the middle drop-down to select it. To navigate to a specific procedure or another member in a particular class, select it from the right drop-down.

Find All References

Visual Studio allows you to find all the references for a particular element in your code editor. You can do this by selecting the code element and pressing Shift+F12 or by right-clicking and selecting Find All References from the context menu.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig24_HTML.jpg
Figure 1-24

Find All References results

The find results are displayed in a tool window as seen in Figure 1-24. The toolbar for the find results tool window as seen in Figure 1-25 is also really helpful.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig25_HTML.jpg
Figure 1-25

References window toolbar

From here you can do the following:
  • Change the search scope

  • Copy the selected referenced item

  • Navigate forward or backward in the list

  • Clear any applicable search filters (filters are added by hovering over a column in the results window and clicking the filter icon that is displayed)

  • Change the grouping of the returned results

  • Keep the search results (new searches are opened in a new tool window)

  • Search the returned results by entering text in the Search Find All References text box

Hovering your mouse of a returned search result will pop up a preview screen of the code. To navigate to a search result, press the Enter key on a reference or double-click it.

Reference Highlighting

Visual Studio makes it really easy to see selected items in the code editor. If you click a variable, for example, you will see all the occurrences of that variable highlighted in the code editor as seen in Figure 1-26.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig26_HTML.jpg
Figure 1-26

Default reference highlighting

But did you know that you can change the color of the highlight from the Options in Visual Studio? Go to Tools, Options, Environment, Fonts and Colors, Highlighted Reference as seen in Figure 1-27.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig27_HTML.jpg
Figure 1-27

Change the Highlighted Reference color

Change the color to yellow and click OK. All the references to the variable you just selected will now be highlighted in yellow.

Go To Commands

I’ll admit that these are probably the commands that I use the least in Visual Studio. All with the exception of Ctrl+G. Go ahead and open Visual Studio, and type Ctrl+G.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig28_HTML.jpg
Figure 1-28

Go To Line

As can be seen in Figure 1-28, a window pops up that allows you to jump to a specific line of code. This is incredibly useful when trying to explain something to another developer not sitting in the same room as you.

The list of Go To commands are as follows:
  • Ctrl+G – Go To Line which allows you to move to the specified line number in the currently active document

  • Ctrl+T or Ctrl+, – Go To All which allows you to move to the specified line, type, file, member, or symbol

  • Ctrl+1, Ctrl+F – Go To File that allows you to move to a specified file in the solution

  • Ctrl+1, Ctrl+R – Go To Recent File allows you to move to a recently visited file in the solution

  • Ctrl+1, Ctrl+T – Go To Type allows you to move to a specific type in the solution

  • Ctrl+1, Ctrl+M – Go To Member allows you to move to the specific member in the solution

  • Ctrl+1, Ctrl+S – Go To Symbol allows you to move to the specific symbol in the solution

  • Alt+PgDn – Go To Next Issue in File

  • Alt+PgUp – Go To Previous Issue in File

  • Ctrl+Shift+Backspace – Go To Last Edit Location

While typing Ctrl+1 might seem slightly finicky, you soon get used to it, and the commands start to feel more natural. Ctrl+Shift+Backspace is another command that I find very useful. This is especially true when editing large code files.

Go To Definition

Go To Definition allows you to jump to the definition of the selected element. Go to the example project for this chapter, and find the click event for the Track button.

Just a reminder that the code for this book can be downloaded from GitHub.

In there you will see that we are working with a class called Package that creates a new package we would like to track.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig29_HTML.jpg
Figure 1-29

Go To Definition

Place your cursor on Package, and hit F12 to jump to the class definition. You can also hold down the Ctrl button and hover over the class name. You will notice that Package becomes a link you can click on. Lastly, if you have your feet up and you only have your mouse to navigate with (the other hand is holding a cup of coffee), you can right-click and select Go To Definition from the context menu.

Peek Definition

Where Go To Definition navigates to the particular definition in question, Peek Definition simply displays the definition of the selected element in a pop-up. Place your cursor on Package and right-click. From the context menu, select Peek Definition.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig30_HTML.jpg
Figure 1-30

Peek Definition pop-up

As can be seen in Figure 1-30, the pop-up window displays the code for the Package class. You can navigate through the code displayed in this pop-up as you would any other code window. You can even use Peek Definition or Go To Definition inside this pop-up.

In the pop-up window, right-click Location, and select Peek Definition from the context menu. The second Peek Definition will start a breadcrumb path as seen in Figure 1-31.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig31_HTML.jpg
Figure 1-31

Breadcrumb path

You can now navigate using the circles and arrows that appear above the Peek Definition pop-up window. The arrows only appear when you hover your mouse over the circles, but this definitely makes it much easier to move between the code windows.

Features and Productivity Tips

Visual Studio is full of existing productivity tips that have been around for years and that some developers do not know about. In this section, we will be looking at some of those.

Track Active Item in Solution Explorer

In Visual Studio, this option is not on by default. As you change the code file you are working in, the file isn’t highlighted in the Solution Explorer. You will know this is the case when you see the following arrows in the toolbar of the Solution Explorer as seen in Figure 1-32.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig32_HTML.jpg
Figure 1-32

Track Active Item in Solution Explorer

Clicking these arrows will highlight the file that you are currently editing in the Solution Explorer. I find this extremely useful, so I let Visual Studio permanently track the current file. To set this, click Tools, Options, Projects and Solutions, General, and check Track Active Item in Solution Explorer.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig33_HTML.jpg
Figure 1-33

Track Active Item Setting

With this setting enabled, the arrows are not displayed in the toolbar of the Solution Explorer.

Hidden Editor Context Menu

When you are in a code file, you can access a variety of menu items by right-clicking and selecting the menu items in the context menu. But did you know that you can hold down Alt+` to bring up a special context menu (that is different from right-click)? It has more editor commands in it as seen in Figure 1-34.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig34_HTML.jpg
Figure 1-34

Special context menu

This gives you a little more control over navigating through errors, methods, etc., in your current code file.

Open in File Explorer

Sometimes you need to quickly get to the actual Visual Studio files of your solution. This might be to go and copy a file from the bin folder or to open a file in another text editor. To do this, you don’t even need to leave Visual Studio. As seen in Figure 1-35, you can right-click the solution and click Open Folder in File Explorer.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig35_HTML.jpg
Figure 1-35

Open Folder in File Explorer

This will open a new File Explorer window where your Visual Studio solution is located.

Finding Keyboard Shortcut Mappings

Sometimes when you use a keyboard shortcut, and nothing happens, you might be using it in the wrong context. To see what keyboard shortcuts are mapped to, head on over to Tools, Options, Environment, Keyboard as seen in Figure 1-36.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig36_HTML.jpg
Figure 1-36

Find keyboard shortcut mappings

Press the shortcut keys, and Visual Studio will show you what the shortcut is currently used for. This is also very useful for assigning new keyboard shortcuts to check that the keyboard shortcut you have in mind is not already bound to another command.

Clipboard History

Visual Studio allows you to access your clipboard history. This is very useful if you have to copy and paste several items repeatedly.

Instead of going back and forth between copy and paste, simply hold down Ctrl+Shift+V to bring up the clipboard history as seen in Figure 1-37.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig37_HTML.jpg
Figure 1-37

Clipboard history

Now you can just select the copied text that you want to paste and carry on with editing your code. The copied item also remains in the clipboard history after pasting.

Go To Window

So this could actually have gone under the Navigating Code section, but I wanted to add it here because it made more sense to discuss it as a productivity tip.

Hold down Ctrl+T and you will see the Go To window pop up. Now type a question mark, and see the options available to you as seen in Figure 1-38.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig38_HTML.jpg
Figure 1-38

Go To Window

You can view the recent files by typing in an r instead of a question mark. Also nice to note is the ability to jump to a specific line of code. You will remember earlier in the chapter that we discussed the Go To commands and Ctrl+G in particular. Here, you can do the same thing by typing in : followed by the line number.

Navigate to Last Edit Location

Earlier on in this chapter, we discussed the Navigate Backward and Navigate Forward commands. This is great, but if you want to navigate to the last place you made an edit in the code file, hold down Ctrl+Shift+Backspace. This will jump to the last place that you made an edit in one of your code files.

Multi-caret Editing

This is a feature that I absolutely love using. Consider the following SQL Create Table Statement:
CREATE TABLE [dbo].[menu](
        [itemName] [varchar](50) NOT NULL,
        [category] [varchar](50) NOT NULL,
        [description] [varchar](50) NOT NULL,
 CONSTRAINT [PK_menu] PRIMARY KEY CLUSTERED
Listing 1-2

Create SQL Table Statement

This is a rather small table, but sometimes we have very large tables that we need to work with. I want to create a simple C# class for this table and need to create some C# properties. Why type out everything when you can copy, paste, and edit all at once.

Paste the column names into a C# class file, and then hold down Ctrl+Alt, and click in front of the first square bracket of each column as can be seen in Figure 1-39.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig39_HTML.jpg
Figure 1-39

Multi-caret selection

The cursor is placed at each line at the position you placed it. Now start typing the property definition. All the lines are edited. After typing public string, hit delete to remove the first square bracket.

I now want to add the { get; set; } portion of my property. I can either do the same multi-caret selection or I can also select one or more characters and hold down Shift+Alt+. to select matching selections as seen in Figure 1-40.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig40_HTML.jpg
Figure 1-40

Selecting matching selections

This now allows me to easily select exactly all the lines I want to edit at the same time and allows me to paste the { get; set; } needed for my properties. I now end up with the completed code as seen in Figure 1-41.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig41_HTML.jpg
Figure 1-41

Completed code properties

Being able to easily select code or place a caret in several places on the same line or across lines allows developers to be really flexible when editing code. Speaking about placing the caret on several places on the same line, it is, therefore, possible to do the following as seen in Figure 1-42.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig42_HTML.jpg
Figure 1-42

Multi-caret selection on the same line

We can now edit everything at once (even if we have selected multiple places on the same line) as seen in Figure 1-43.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig43_HTML.jpg
Figure 1-43

Multi-caret editing on the same line

Holding down Ctrl+Z will also work to undo everything at once. If you want to insert carets at all matching selections, you can select some text and hold down Shift+Alt+; to select everything that matches your current selection as seen in Figure 1-44.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig44_HTML.jpg
Figure 1-44

Insert carets at all matching selections

I selected the text “cat” and held down Shift+Alt+; and Visual Studio selected everything that matches. As you can see, it also selected the category property, which I don’t want to be selected. In this instance, Shift+Alt+. will allow me to be more specific in my selection.

If you find yourself forgetting the keyboard shortcuts, you can find them under the Edit menu. Click Edit, Multiple Carets to see the keyboard shortcuts.

Features in Visual Studio 2019

Visual Studio 2019 comes packed with a few very nice productivity features. A lot of thought has been put into making Visual Studio easy to navigate and to find things in Visual Studio 2019. The first feature I want to have a look at is Visual Studio Search.

Visual Studio Search

I think that we can all agree that more speed equals improved productivity. The faster I can access a menu item, and the less time I have to spend looking for something, the more my productivity increases. This is where Visual Studio Search comes in.

If you hold down Ctrl+Q you will jump to the search bar where you can immediately start typing as seen in Figure 1-45.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig45_HTML.jpg
Figure 1-45

Visual Studio Search

Visual Studio will perform the required search and display the results to you that you can further filter by clicking the Menus, Components, or Templates tabs. Visual Studio performs a fuzzy search, which means that even if you misspell a word, chances are that Visual Studio will know what you intended to type and return the correct results for you.

Solution Filters

Sometimes we have to work on Solutions that contain a lot of projects. More often than not, you as a developer will not be working on every project in that specific solution. This is where Solution Filters come in. They allow you to only load the projects that you care about or are actively working on. Consider the currently loaded solution as seen in Figure 1-46.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig46_HTML.jpg
Figure 1-46

AcmeCorpShipping Solution Unfiltered

You can see that all the projects are loaded in this solution. If we only work on the ShipmentLocator and ShipMethodLogic projects, we can create a Solution Filter to only load those projects. Right-click the projects that you don’t work on, and click Unload Project from the context menu. Your solution will now look as in Figure 1-47.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig47_HTML.jpg
Figure 1-47

AcmeCorpShipping Solution with unloaded projects

Now, with the projects unloaded that you do not work on, right-click the solution and select Save As Solution Filter as seen in Figure 1-48.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig48_HTML.jpg
Figure 1-48

Save As Solution Filter

Visual Studio will now create a new type of solution file with an .slnf file extension as seen in Figure 1-49.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig49_HTML.jpg
Figure 1-49

Save as Solution Filter file

When you open your project using the Solution Filter, you will see as in Figure 1-50 that only the projects you selected to keep will be loaded.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig50_HTML.jpg
Figure 1-50

Filtered solution

Now with the filtered solution, if you click the solution, you will see that you can Load App Projects, Show Unloaded Projects, or Load Project Dependencies from the context menu as seen in Figure 1-51.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig51_HTML.jpg
Figure 1-51

Filtered solution context menu

You still have full control of the filtered solution from the context menu and can easily load the full solution as needed.

Visual Studio IntelliCode

Visual Studio IntelliCode is a really nice feature that has been added to Visual Studio. Microsoft calls it AI-assisted development because it uses machine learning to figure out what you are most likely to use next and putting that suggestion at the top of your completion list. These are usually displayed as starred recommendations.

Without IntelliCode, when you dot on an object such as our package object in the AcmeCorpShipping solution, you will see the usual completion list that Visual Studio pops up as seen in Figure 1-52.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig52_HTML.jpg
Figure 1-52

Visual Studio completion list

In Visual Studio 2019, hit Ctrl+Q and type IntelliCode to search for IntelliCode. Select IntelliCode Model Management from the search results. You can also go to View, Other Windows and click IntelliCode Model Management. You will then see the Visual Studio IntelliCode window pop-up inside Visual Studio as seen in Figure 1-53.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig53_HTML.jpg
Figure 1-53

Visual Studio IntelliCode

Click Create new model to allow Visual Studio IntelliCode to analyze your code and create the model. When Visual Studio has completed the analysis and created the model, you will be able to share the model with other developers (which is great for teams), delete the model, or retrain the model as seen in Figure 1-54.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig54_HTML.jpg
Figure 1-54

Visual Studio IntelliCode model completed

This time around, if you dot on the package in the AcmeCorpShipping solution, you will see the starred recommendations from IntelliCode as seen in Figure 1-55.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig55_HTML.jpg
Figure 1-55

IntelliCode starred recommendations

Compare this to the Visual Studio completion list in Figure 1-52. You can see that IntelliCode has identified the TrackPackage method as the most likely method that you will want to use.

IntelliCode uses open source GitHub projects with 100 stars or more to distill the wisdom of the community in order to generate recommendations for your code. To demonstrate how clever Visual Studio IntelliCode is, have a look at Figure 1-56.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig56_HTML.jpg
Figure 1-56

IntelliCode acting on a string

IntelliCode knows the most likely things I would want to do with a string variable and places those methods at the top of the suggestion list. The suggestions look quite a bit different when I am working with a string array as seen in Figure 1-57.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig57_HTML.jpg
Figure 1-57

IntelliCode acting on a string array

This means that IntelliCode takes the current context into account when suggesting methods in the completion list. If you would like to view the model generated by IntelliCode, you can head on over to %TEMP%Visual Studio IntelliCode. In one of the created folders, you will find a subfolder called “UsageOutput.” Look for a JSON file in the “UseageOutput” folder. This is where the contents of the extracted data is stored for your model.

It is important to note that Microsoft does not receive any of your code. IntelliCode only uploads data and information about your code to Microsoft’s servers. All your code remains on your computer.

IntelliCode is a productivity feature that will definitely benefit developers on a day-to-day basis.

Visual Studio Live Share

During my years of writing code, I have often had the need to explain some portion of logic or feature of the code I am working with, to another developer. This usually involves them having to get a copy of the code base from source control and us having to direct each other over a Skype call and quote line numbers in order to collaborate properly.

To find out more about Visual Studio Live Share, or to download a copy for Visual Studio Code or Visual Studio 2017, go to https://visualstudio.microsoft.com/services/live-share/.

Visual Studio Live Share is included by default in Visual Studio 2019. Visual Studio Live Share does not require developers to be all “set up” in order to assist each other or to collaborate on projects. This means that a developer running Visual Studio Code on a Linux machine can collaborate with another developer running Visual Studio 2019 on a Windows 10 machine.

To start a Visual Studio Live Share session, you need to click the Live Share icon in the top right corner of Visual Studio 2019 as can be seen in Figure 1-58.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig58_HTML.jpg
Figure 1-58

Visual Studio Live Share Icon

When you click the icon, Visual Studio starts up Live Share, and the progress is indicated as can be seen in Figure 1-59.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig59_HTML.jpg
Figure 1-59

Visual Studio Live Share In Progress

When the sharing link has been generated, Visual Studio will display a notification as seen in Figure 1-60.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig60_HTML.jpg
Figure 1-60

Visual Studio Live Share Link Generated

It is copied to the clipboard by default, but you can copy it again, make it read-only, or learn more about secure sharing. When you share the link with a fellow developer, they simply have to paste the link into a browser to start the collaboration. Figure 1-61 shows the browser after pasting the link.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig61_HTML.jpg
Figure 1-61

Starting Visual Studio Live Share session

In this example, I am sharing the link with a developer that is running Visual Studio Code on Linux Mint. Linux then pops up a Launch Application notification as seen in Figure 1-62.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig62_HTML.jpg
Figure 1-62

Launch Application Notification on Linux

Visual Studio Code is already installed on the Linux machine; therefore, the Launch Application notification offers that as the default choice for opening vsls links. When you click the Open Link button, Visual Studio Code launches, and your Live Share session is initiated as seen in Figure 1-63. Visual Studio Code then has a copy of the code that I am sharing on my machine.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig63_HTML.jpg
Figure 1-63

Visual Studio Live Share session

As Jason navigates his way around the code, I can see this in my code via a marker that pops up momentarily displaying his name as seen in Figure 1-64.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig64_HTML.jpg
Figure 1-64

I can see Jason's current position in the code

Over in Visual Studio Code, Jason can see where I am via a similar marker that momentarily pops up my name as seen in Figure 1-65.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig65_HTML.jpg
Figure 1-65

Jason can see my current position in the code

This allows us to know what the other is doing and where we are working at any given time. In Visual Studio 2019, I now also have a new Live Share tab displayed as seen in Figure 1-66.
../images/487681_1_En_1_Chapter/487681_1_En_1_Fig66_HTML.jpg
Figure 1-66

Live Share tab in Visual Studio 2019

From there, I can end the Live Share session, share the terminal, manage shared servers, focus participants, or copy the sharing link again. At any time, I am in total control of what I share. It is also important to note that my code lives on my machine. It is not saved on the participant’s machine.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.13.113