
- •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 |
•\ |
Use the Mac build host to compile and sign the iOS app using the |
|
build tools. |
•\ |
Invoke the Mac builds securely via SSH. |
•\ |
If an iOS device is plugged into the Mac, Visual Studio 2022 is notified |
|
of this, and the iOS toolbar will update accordingly. |
For more information on enabling the Mac build host in Visual Studio using a network-connected Mac, see the following link on the Microsoft documentation site: https://docs.microsoft.com/en-us/dotnet/maui/ios/pair-to-mac.
As of the writing of this book, Visual Studio 2022 for Mac was still in preview. For more information on Visual Studio 2022 for Mac, see the following link: https://visualstudio.microsoft.com/vs/mac/preview/.
Visual Studio 2022 for Mac will bring fully native macOS UI applications built on
.NET 6, including native support for the Apple M1 chip to Mac developers.
Consuming REST Services in MAUI
Modern applications often use REST Web Services to provide some functionality to users. This can be anything from accessing data to providing cloud storage. When implementing this on a mobile device, you would need to determine if the device is connected to the Internet. If it is, then only can you consume the REST Web Service.
When writing any application, consuming a Web Service is quite straightforward. If this is your first time working with MAUI, you might be wondering how to accomplish this. MAUI will feel familiar if you’re used to working with ASP.NET Core Web Applications and dependency injection.
In this section, I will show you how to consume a Web Service to get the current weather and ten-day forecast for Los Angeles using the Weather API at www.weatherapi. com. You need to create an account to get an API Key to use in your REST calls. I will not go through exactly how to do this. If you do not want to use the Weather API, you can choose another suitable service to consume. The focus here is consuming a Web Service, not the type of service being consumed. The logic detailed here remains the same. Let’s have a look at the complete application first.
79

Chapter 2 Working with Visual Studio 2022
The Complete Weather App
When running the application for the first time, you will see an empty screen, as illustrated in Figure 2-20.
Figure 2-20. Starting the Weather Forecast App
The reason for this is so that I can show you how to add a command to click the Refresh button.
After you click the Refresh button, the application will call the weather service API and return the data to the UI for display, as seen in Figure 2-21.
80

Chapter 2 Working with Visual Studio 2022
Figure 2-21. The Refreshed Weather App
As seen in Figure 2-22, the layout of the MAUI solution is straightforward. When creating the solution, it will be created with the Resources and Platforms folders. The Resources folder, as the name suggests, will contain any assets required for the
application, such as images, icons, fonts, and so on. The Platforms folder contains the platform-specific code for Android, iOS, Mac Catalyst, Tizen, and Windows.
81

Chapter 2 Working with Visual Studio 2022
Figure 2-22. The Weather App solution
The Target Platforms
It is also worth noting that you do not need to carry any dead weight in your project. If you are creating an application that only runs on Android, iOS, and Mac Catalyst, you can remove unnecessary platforms. Edit your csproj file by right-clicking the project in the Solution Explorer and selecting Edit Project File from the context menu. There you
82