Reader small image

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

Product typeBook
Published inMar 2024
PublisherPackt
ISBN-139781835080443
Edition2nd Edition
Right arrow
Authors (2):
Hector Uriel Perez Rojas
Hector Uriel Perez Rojas
author image
Hector Uriel Perez Rojas

Hector is an experienced senior developer, with more than 10 years of experience in developing desktop, web, and mobile solutions with the .NET platform. He was recognized with the Microsoft MVP award for two consecutive years in 2021 and 2022. He is an active member of the .NET community and is the founder of El Camino Dev and Devs School academies.
Read more about Hector Uriel Perez Rojas

Miguel Angel Teheran Garcia
Miguel Angel Teheran Garcia
author image
Miguel Angel Teheran Garcia

Miguel Angel Teheran Garcia is a solutions Architect and Technical Lead recognized as a Microsoft MVP, C# corner MVP, and Alibaba Cloud MVP. He is a member of the Avanet community in Medellín and an active member of tech events in Colombia. He has also been a speaker at different conferences around Latin America.
Read more about Miguel Angel Teheran Garcia

View More author details
Right arrow

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 2024Publisher: PacktISBN-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.
undefined
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 €14.99/month. Cancel anytime

Authors (2)

author image
Hector Uriel Perez Rojas

Hector is an experienced senior developer, with more than 10 years of experience in developing desktop, web, and mobile solutions with the .NET platform. He was recognized with the Microsoft MVP award for two consecutive years in 2021 and 2022. He is an active member of the .NET community and is the founder of El Camino Dev and Devs School academies.
Read more about Hector Uriel Perez Rojas

author image
Miguel Angel Teheran Garcia

Miguel Angel Teheran Garcia is a solutions Architect and Technical Lead recognized as a Microsoft MVP, C# corner MVP, and Alibaba Cloud MVP. He is a member of the Avanet community in Medellín and an active member of tech events in Colombia. He has also been a speaker at different conferences around Latin America.
Read more about Miguel Angel Teheran Garcia