
- •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
Web Applications
If you need to create web-based applications, you will create an ASP.NET Web Application. If you look at the project templates, you will notice that you can create an ASP.NET Web Application that runs on .NET 6 using Razor Pages, as seen in Figure 2-12.
Figure 2-12. ASP.NET Core Web Application template
But wait a minute, didn’t we just mention that it’s now called .NET and no longer
.NET Core? With all the mentioning of .NET 6, we can easily confuse the fact that when referring to ASP.NET Core 6.0, Microsoft still uses “Core” in the name. While the overall platform does not use “Core” in the naming, the specific application model names still do when referring to ASP.NET Core 6.0 and Entity Framework Core 6.0.
If you want to use a Model-View-Controller approach to create your web application, you can select the ASP.NET Core Web App (Model-View-Controller) template, as seen in Figure 2-13.
Figure 2-13. ASP.NET Core MVC Web App template
As seen in the template description, this template allows you to create a web application using Views and Controllers.
Class Library
The following project template we will look at is the Class Library. It is worth noting that the Class Library creates a DLL that you can reuse in your applications. This is the purpose of a Class Library project.
73

Chapter 2 Working with Visual Studio 2022
Many more project templates are available in Visual Studio and depend on the workloads you have installed.
As you see in Figure 2-14, the Class Library can be based on .NET, .NET Framework, or .NET Standard.
Figure 2-14. Class Library projects
You might be wondering what the differences are between the various project templates. You will find a hint when you look at the tags. The Class Library running the
.NET Framework will create a DLL that only works on Windows machines.
The Class Library running .NET or .NET Standard will create a library that will run on Windows, Linux, and macOS (it’s, therefore, cross-platform).
.NET Standard’s motivation was to establish more uniformity in the .NET ecosystem. With .NET 6 going forward, this introduces a different approach for uniformity and negates the need for .NET Standard in many cases.
The Class Library running on .NET Standard will allow you to share code between the .NET Framework and other .NET implementations, such as .NET Core. It is worth noting, however, that no new versions of .NET Standard will be released but that .NET 6 and future versions of .NET will still support .NET Standard 2.1 and earlier.
74

Chapter 2 Working with Visual Studio 2022
For more information regarding .NET Standard, have a look at the following article on Microsoft Docs: https://docs.microsoft.com/en-us/dotnet/standard/net- standard.
There are many more project templates to choose from, and the project templates you see will depend on your installed workloads. Explore some of the different workloads available to you, and see what project templates are available after installing a particular workload.
MAUI
The last project template we will look at is probably the most exciting, and we will see how to create a .NET MAUI application in the next section. MAUI stands for Multiplatform App UI or simply .NET MAUI. .NET MAUI enables developers to build
natively compiled iOS, Android, macOS, and Windows apps using C# and XAML in one codebase. It automatically changes the UI of your application to adapt to the native platform it’s running on without having to use any additional code.
.NET MAUI applications for iOS do require a Mac build host. The following example will run the MAUI application we create using the Android Emulator.
To create a .NET MAUI application, you will need the latest Visual Studio 2022 17.3. You also need to ensure that you have installed the .NET Multiplatform App UI development workload, as seen in Figure 2-15.
Figure 2-15. The .NET MAUI workload
It’s a significant workload. When writing this book, it clocked in at just under 10 GB, so make sure you have enough hard drive space.
75