
- •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 2 Working with Visual Studio 2022
Being able to add custom tokens in Visual Studio, as well as applying a priority to each, allows you to be very specific with comments that contain tokens. This way, you can significantly increase the ease and efficiency of navigating a large code base.
The Server Explorer
As the name suggests, the Server Explorer provides a quick and easy way of accessing servers. You can use it to test connections and view SQL Server databases or any databases that have the ADO.NET provider installed.
You can access the Server Explorer by holding down Ctrl+Alt+S or by going to the View menu and clicking Server Explorer.
Figure 2-63 shows that the Server Explorer offers access to Event Logs, Message Queues, Performance Counters, and Services on my local machine (MSI). It also provides access to my Azure subscriptions.
Figure 2-63. Server Explorer
140

Chapter 2 Working with Visual Studio 2022
I have a local instance of SQL Server installed, so now I can connect to this instance right from within Visual Studio by clicking Connect to Database.
This displays a window allowing you to choose a data source, as seen in Figure 2-64. You can connect to various data sources, but we are only interested in Microsoft SQL Server for now. Select that from the list and click Continue.
Figure 2-64. Choose Data Source
The following window (Figure 2-65) allows you to define your connection to the database. Here, you need to specify the server name and the authentication type, and if SQL Server Authentication is selected, provide the username and password.
141

Chapter 2 Working with Visual Studio 2022
Figure 2-65. Add Connection
This allows you to select a database from the list to connect to. You can click the Test Connection button to check if the connection settings are correct.
After adding the database to your Server Explorer, you will see the instance added to your list from where you can expand the various nodes to view Tables, Views, and Stored Procedures, as seen in Figure 2-66.
142

Chapter 2 Working with Visual Studio 2022
Figure 2-66. Database added to Server Explorer
By double-clicking a table, Visual Studio displays the table designer for you and a create table SQL statement, as seen in Figure 2-67.
143

Chapter 2 Working with Visual Studio 2022
Figure 2-67. Table designer
From this window, you can easily update the table. The create table statement in Figure 2-67 is listed in Listing 2-25.
Listing 2-25. Create Table Statement
CREATE TABLE [dbo].[menu] ( |
|
|
[itemName] |
VARCHAR (50) |
NOT NULL, |
[category] |
VARCHAR (50) |
NOT NULL, |
[price] |
DECIMAL (5, 2) NULL, |
|
CONSTRAINT |
[PK_menu] PRIMARY KEY CLUSTERED ([itemName] ASC) |
|
); |
|
|
We can now modify the menu table by altering the SQL statement as shown in Listing 2-26.
144

Chapter 2 Working with Visual Studio 2022
Listing 2-26. Modified Create Table Statement
CREATE TABLE [dbo].[menu] ( |
|
||
[itemName] |
VARCHAR |
(50) |
NOT NULL, |
[category] |
VARCHAR |
(50) |
NOT NULL, |
[price] |
DECIMAL |
(5, 2) NULL, |
|
[priceCategory] |
VARCHAR (5) NULL, |
||
CONSTRAINT |
[PK_menu] PRIMARY KEY CLUSTERED ([itemName] ASC) |
||
); |
|
|
|
I want to add a price category field to the table. When I modify the create table statement, I see the changes reflected in the table designer, as seen in Figure 2-68.
Figure 2-68. Table design updated
The changes have not been applied to my table yet. To update the table, I need to click the Update button.
This allows me to preview the database updates, as seen in Figure 2-69. If you do not want to let Visual Studio update the table, you can have it generate the script by clicking the Generate Script button. Alternatively, you can go ahead and click the Update Database button.
145

Chapter 2 Working with Visual Studio 2022
Figure 2-69. Preview Database Updates
This will then start the process of updating the database table with the changes you made.
After the update, you can see the results in the Data Tools Operations window, as seen in Figure 2-70. From here, you can view the script and the results.
Figure 2-70. Data Tools Operations
146