
- •Table of Contents
- •About the Author
- •About the Technical Reviewer
- •Acknowledgments
- •Introduction
- •Installing Visual Studio
- •Visual Studio 2022 System Requirements
- •Operating Systems
- •Hardware
- •Supported Languages
- •Additional Notes
- •Visual Studio Is 64-Bit
- •Full .NET 6.0 Support
- •Using Workloads
- •The Solution Explorer
- •Toolbox
- •The Code Editor
- •New Razor Editor
- •What’s Available?
- •Hot Reload
- •Navigating Code
- •Navigate Forward and Backward Commands
- •Navigation Bar
- •Find All References
- •Find Files Faster
- •Reference Highlighting
- •Peek Definition
- •Subword Navigation
- •Features and Productivity Tips
- •Track Active Item in Solution Explorer
- •Hidden Editor Context Menu
- •Open in File Explorer
- •Finding Keyboard Shortcut Mappings
- •Clipboard History
- •Go To Window
- •Navigate to Last Edit Location
- •Multi-caret Editing
- •Sync Namespaces to Match Your Folder Structure
- •Paste JSON As Classes
- •Enable Code Cleanup on Save
- •Add Missing Using on Paste
- •Features in Visual Studio 2022
- •Visual Studio Search
- •Solution Filters
- •Visual Studio IntelliCode
- •Whole Line Completions
- •Visual Studio Live Share
- •Summary
- •Visual Studio Project Types
- •Various Project Templates
- •Console Applications
- •Windows Forms Application
- •Windows Service
- •Web Applications
- •Class Library
- •MAUI
- •Creating a MAUI Application
- •Pairing to Mac for iOS Development
- •Consuming REST Services in MAUI
- •The Complete Weather App
- •The Target Platforms
- •The Required NuGet Package
- •The Weather Models
- •The WeatherService
- •The MainViewModel
- •Registering Dependencies
- •Building the MainPage View
- •Using SQLite in a MAUI Application
- •The ToDoItem Model
- •The ToDoService
- •The MainViewModel
- •Registering Dependencies
- •Building the MainPage View
- •Managing NuGet Packages
- •Using NuGet in Visual Studio
- •Hosting Your Own NuGet Feeds
- •Managing nmp Packages
- •Creating Project Templates
- •Creating and Using Code Snippets
- •Creating Code Snippets
- •Using Bookmarks and Code Shortcuts
- •Bookmarks
- •Code Shortcuts
- •Adding Custom Tokens
- •The Server Explorer
- •Running SQL Queries
- •Visual Studio Windows
- •C# Interactive
- •Code Metrics Results
- •Maintainability Index
- •Cyclomatic Complexity
- •Class Coupling
- •Send Feedback
- •Personalizing Visual Studio
- •Adjust Line Spacing
- •Document Management Customizations
- •The Document Close Button
- •Modify the Dirty Indicator
- •Show Invisible Tabs in Italics in the Tab Drop-Down
- •Colorize Document Tabs
- •Tab Placement
- •Visual Studio Themes
- •Summary
- •Setting a Breakpoint
- •Step into Specific
- •Run to Click
- •Run to Cursor
- •Force Run to Cursor
- •Conditional Breakpoints and Actions
- •Temporary Breakpoints
- •Dependent Breakpoints
- •Dragging Breakpoints
- •Manage Breakpoints with Labels
- •Exporting Breakpoints
- •Using DataTips
- •Visualizing Complex Data Types
- •Bonus Tip
- •Using the Watch Window
- •The DebuggerDisplay Attribute
- •Evaluate Functions Without Side Effects
- •Format Specifiers
- •dynamic
- •hidden
- •results
- •Diagnostic Tools
- •CPU Usage
- •Memory Usage
- •The Events View
- •The Right Tool for the Right Project Type
- •Immediate Window
- •Attaching to a Running Process
- •Attach to a Remote Process
- •Remote Debugger Port Assignments
- •Remote Debugging
- •System Requirements
- •Download and Install Remote Tools
- •Running Remote Tools
- •Start Remote Debugging
- •Summary
- •Creating and Running Unit Tests
- •Create and Run a Test Playlist
- •Testing Timeouts
- •Using Live Unit Tests
- •Using IntelliTest to Generate Unit Tests
- •Focus IntelliTest Code Exploration
- •How to Measure Code Coverage in Visual Studio
- •Summary
- •Create a GitHub Account
- •Create and Clone a Repository
- •Create a Branch from Your Code
- •Creating and Handling Pull Requests
- •Multi-repo Support
- •Compare Branches
- •Check Out Commit
- •Line Staging
- •Summary
- •Index

Chapter 1 Getting to Know Visual Studio 2022
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 WinForms application, you will notice that you have a Toolbox at your disposal (Figure 1-15).
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.
20

Chapter 1 Getting to Know Visual Studio 2022
If you do not like the default layout of the Toolbox, you can right-click the tab or an individual item in the Toolbox and perform one of several actions from the context menu as seen in Figure 1-16.
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.
21

Chapter 1 Getting to Know Visual Studio 2022
The Code Editor
Let’s add some basic UI components to our WinForms 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.
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 WinForms application called Form1.cs. Add the 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.
22
Chapter 1 Getting to Know Visual Studio 2022
Listing 1-1. The Code-Behind Form1.cs
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-");
}
23

Chapter 1 Getting to Know Visual Studio 2022
The underlined code is code that Visual Studio is making suggestions for improvement on.
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.
24

Chapter 1 Getting to Know Visual Studio 2022
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.
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.
25