Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Visual Studio 2022 - Second Edition

You're reading from  Hands-On Visual Studio 2022 - Second Edition

Product type Book
Published in Mar 2024
Publisher Packt
ISBN-13 9781835080443
Pages 336 pages
Edition 2nd Edition
Languages
Authors (2):
Hector Uriel Perez Rojas Hector Uriel Perez Rojas
Profile icon Hector Uriel Perez Rojas
Miguel Angel Teheran Garcia Miguel Angel Teheran Garcia
Profile icon Miguel Angel Teheran Garcia
View More author details

Table of Contents (19) Chapters

Preface 1. Part 1: Visual Studio Overview
2. Chapter 1: Getting Started with Visual Studio 2022 3. Chapter 2: Creating Projects and Templates 4. Chapter 3: Debugging and Profiling Your Apps 5. Part 2: Tools and Productivity
6. Chapter 4: Adding Code Snippets 7. Chapter 5: Coding Efficiently with AI and Code Views 8. Chapter 6: Using Tools for Frontend and Backend Development 9. Chapter 7: Styling and Cleanup Tools 10. Chapter 8: Publishing Projects 11. Part 3: GitHub Integration and Extensions
12. Chapter 9: Implementing Git Integration 13. Chapter 10: Sharing Code with Live Share 14. Chapter 11: Working with Extensions in Visual Studio 15. Chapter 12: Using Popular Extensions 16. Chapter 13: Learning Keyboard Shortcuts 17. Index 18. Other Books You May Enjoy

Creating Projects and Templates

A template within VS is a set of files, references, project properties, and compilation options for working with a particular technology. Templates provide us with basic code to work with and act as a guide that we can follow and complete by including our business logic and requirements. Different templates are installed according to the workloads that have been selected during VS installation, although there are templates that will be installed by default, such as class libraries. Depending on the project or technology we want to use, we will find different template options to choose from. Selecting the right template that fits your needs is the best action that you can take to evade technical debts and future issues in your architecture.

In this chapter, we will analyze the main templates provided by VS. In addition, we will understand how to pick the best template for our projects, considering the scope, requirements, and expertise of the team...

Technical requirements

To follow along in this chapter, you must have previously installed VS 2022, as described in Chapter 1, Getting Started with Visual Studio 2022.

You must also have the ASP.NET and web development, .NET Multi-platform App UI development, and .NET desktop development workloads installed. Throughout the chapter, you will see what types of templates are available according to the installed workload.

Selecting and searching for templates

As mentioned in the introduction of this chapter, VS has many templates that we can use with .NET and other technologies, depending on the type of project you are working on.

To explore the templates in VS 2022, just open VS and select the Create a new project option:

Figure 2.1 – The VS "Create a new project" option

Figure 2.1 – The VS "Create a new project" option

After selecting this option, we will see a list of templates to choose from for creating our new project, as shown in Figure 2.2. Similarly, on the left side, we will be able to see templates we have recently selected, with the option to pin or unpin each template so that we can quickly select templates that we use the most:

Figure 2.2 – The option to pin or unpin a template in the "Recent project templates" section

Figure 2.2 – The option to pin or unpin a template in the "Recent project templates" section

In Figure 2.2, we also see a search bar at the top for filtering the different templates. If you know the name of the technology...

Templates for web development

The first group we will analyze is the templates related to web development. To install these templates, with the VS Installer, you must select the ASP.NET and web development workload, as shown in Figure 2.6:

Figure 2.6 – Selecting the "ASP.NET and web development" workload

Figure 2.6 – Selecting the "ASP.NET and web development" workload

The description mentions that the templates of this workload allow you to create projects using ASP.NET Core, ASP.NET, HTML/JavaScript projects, and Containers.

Let’s look at the main categories of templates that can be found with this workload next.

Templates for ASP.NET Core web applications

ASP.NET Core is a multiplatform web technology for creating modern applications using .NET, with which is possible to create standard web applications. The main templates that we can find to develop this type of application are as follows:

  • ASP.NET Core Web App (Razor Pages): This is the template for working with ASP.NET Core...

Templates for multiplatform development

.NET MAUI is Microsoft’s framework that allows the development of multiplatform applications – that is, applications for Android, iOS, and Windows mainly, although it is possible to deploy applications on other platforms such as Tizen and macOS.

In order to be able to use these templates, in the Visual Studio Installer, we must select the .NET MAUI Multi-platform App UI development workload, as shown in Figure 2.21:

Figure 2.21 – The ".NET MAUI Multi-platform App UI development" workload

This type of project uses markup files with a .xaml extension for the definition of the graphical interface while C# code is used to specify the business logic.

For example, to display text in a .xaml file, a syntax like the following is used:

<Label   FontAttributes="Bold"
   FontSize="30"
   Text="Packt"
 ...

Templates for desktop development

The last category of templates we will look at are desktop development templates. To install these templates on your computer, you must select the workload called .NET desktop development, as shown in Figure 2.25:

Figure 2.25 – The ".NET desktop development" workload

Figure 2.25 – The ".NET desktop development" workload

This workload includes templates for two technologies with many years of maturity: Windows Forms and Windows Presentation Foundation (WPF).

Windows Forms is an old but still widely used technology among .NET developers, since it allows us to create desktop stacks quickly thanks to its drag-and-drop solution. The main templates for Windows Forms development include the following:

  • Window Forms App: This is the base template for creating a new Windows Forms application. It includes a file so that you can begin to design your first window quickly.
  • Windows Forms Control Library: A project that allows us to manage customized controls...

Summary

In this chapter, we have seen the main workloads and the most common templates available in VS for developing different types of projects.

We have seen specific templates for web development, for creating ASP.NET Core applications, SPAs, and web APIs. Undoubtedly, ASP.NET and web development is one of the workloads that has more templates available, because VS is not only designed for .NET developers but also for web developers in general.

We also analyzed templates that allow cross-platform development with .NET MAUI, allowing the deployment of applications for Android, iOS, and Windows mainly. Finally, we saw which templates are available for desktop development.

In the next chapter, you will learn about tools available in VS that will allow you to debug your applications to detect errors, as well as tools to analyze the performance of your applications.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Hands-On Visual Studio 2022 - Second Edition
Published in: Mar 2024 Publisher: Packt ISBN-13: 9781835080443
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}