
- •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
This is the power that NuGet provides. You, as a developer, need to consider using it if you do not already do so.
Hosting Your Own NuGet Feeds
Sometimes, you might need to create and share packages only available to a limited audience. Think of the developers inside your organization. Perhaps the company you work with does not allow the sharing of code with a public audience. Perhaps the code you want to share is specific to your organization and unsuitable for a public audience. Whatever the situation, NuGet supports private feeds in the following ways:
•\ |
Local feed – On a network file share. |
•\ |
NuGet.Server – On a local HTTP server. |
•\ |
NuGet gallery – Hosted on an Internet server using the NuGet Gallery |
|
project, you can manage users and features to allow searching and |
|
exploring available packages similar to nuget.org. |
Other NuGet hosting solutions support the creation of remote private feeds. Some of these are
•\ |
Azure Artifacts |
•\ |
MyGet – https://myget.org/ |
•\ |
ProGet – https://inedo.com/proget |
•\ |
TeamCity – www.jetbrains.com/teamcity/ |
For a complete list of NuGet hosting products and for more information on creating your NuGet feeds, have a look at the following link on Microsoft Docs: https://docs. microsoft.com/en-us/nuget/hosting-packages/overview.
Managing nmp Packages
In a similar vein to NuGet, nmp allows you to install and manage packages that can be used in Node.js as well as ASP.NET Core apps. If you are unfamiliar with nmp, you can read more about it by looking at the nmp documentation at https://docs.npmjs.com/.
118

Chapter 2 Working with Visual Studio 2022
With Visual Studio 2022, the nmp package manager is available for CLI-based projects. This allows you to download nmp modules similar to the way you would download NuGet packages in an ASP.NET Core project.
The package manager can be opened by right-clicking the nmp node in the Solution Explorer as seen in Figure 2-40.
Figure 2-40. Installing new nmp packages
You can now search for nmp packages and then select one to install as seen in Figure 2-41. Clicking the Install Package button installs the package.
119

Chapter 2 Working with Visual Studio 2022
Figure 2-41. Searching for nmp packages
Creating Project Templates
Sometimes, developers create class libraries and code that they need to use repeatedly across various new projects. What developers end up doing is copying and pasting code into new class libraries. However, there is an easier way to create projects that reuse code you have previously written.
Enter Visual Studio project templates. These templates allow developers to speed up their development by including previously written code in new projects. Let’s assume we have created a project called ProjectUtilities (as seen in Figure 2-42) that contains various helper methods.
120

Chapter 2 Working with Visual Studio 2022
Figure 2-42. ProjectUtilities project
We will need to use this Class Library over and over in various projects. So I have decided to create a project template from it.
From the Project menu, click Export Template, as seen in Figure 2-43.
121

Chapter 2 Working with Visual Studio 2022
Figure 2-43. Export template
The Export Template Wizard is displayed as seen in Figure 2-44. This allows you to specify which template you need to create. The options are creating a Project template or an Item template. A Project template is what we are after in this example, but you can also create an Item template. This allows you to add the code via the Add New Item dialog box in Visual Studio.
122

Chapter 2 Working with Visual Studio 2022
Figure 2-44. Export Template Wizard
For this example, however, we keep the Project template option selected and select the project to export from the drop-down list. This drop-down lists all the projects in my Visual Studio solution. Select the ProjectUtilities project, and click the Next button.
The following window is where one can enter various template options (Figure 2-45). Here, I can give the template a proper name and description, specify the icon and preview images, and select to import the template into Visual Studio automatically. Click Finish to create the new project template.
123

Chapter 2 Working with Visual Studio 2022
Figure 2-45. Add template options
The next time I create a new project in Visual Studio, I can search for my Custom project template (Figure 2-46) and have it available for me to select.
124