Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
strauss_d_getting_started_with_visual_studio_2022_learning_a.pdf
Скачиваний:
123
Добавлен:
26.06.2023
Размер:
17.04 Mб
Скачать

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