ASP.NET Core For Managers
It can be daunting for a developer or manager to try to decipher and choose one of the new frameworks available in .NET Core and Visual Studio. As developer teams continue to maintain existing web solutions, they occasionally need to create or rewrite a new ASP.NET web application. Perhaps they are replacing an old Active Server Pages (ASP), WebForms (ASPX) application, or .NET Framework MVC application. The question is – which project template is best?
Which One Should You Use and Why?
Selecting A Project Template
“When a developer opens Visual Studio to create a new web project, many project templates appear. You can install additional project templates from Microsoft and other third parties into Visual Studio. However, here are the stock options in Visual Studio 2022.”
NOTE: Initially, you can only see half of them. You will need to scroll down to see the rest of the project templates, and there are a lot of them!
Create A New Project
Something To Remember
Additional templates can be downloaded and installed from “Visual Studio Marketplace.”
Pay special to the languages (C#, en-us) and frameworks (.NET Framework, Core) they support.
A Note About WCF
The WCF projects are .NET Framework only. Other than Mono projects (https://www.mono-project.com/) that do run .NET apps on Linux, iOS, and Windows, there is limited support for WCF. These projects require Windows to run them.
Configure Your New Project
On Release of .NET 5 All “.NET Conf 2020” Presentations Were Published For Viewing.
Save This Link…
All the 30-minute presentations were recorded and published on the dotNET YouTube channel.
Microsoft has recently changed to a “rapid release” cycle for .NET Core.
They are now releasing a new major version of .NET every year in November. At the time of writing, plan on .NET 6 being released in November 2021, and then .NET 7 will be released in November 2022.
NOTE: Keep in mind that the version of .NET you choose will also lock you into a version of the C# compiler, which is why (starting with Visual Studio 2019) you cannot choose which C# compiler you will use with the newer versions of .NET.
C# Language Versioning
NOTE: You can learn more about C# versioning here: (Click Here)
Selecting A Project Template (Continued)
So which project template should you choose? What features do they support? What are the advantages/disadvantages between the choices?
Let’s summarize each one!
ASP.NET Core Web App
NOTE: Web Pages may remind you of classic .asp pages but with the improved Razor view engine and WebForm’s master pages – now called layout files.
Files placed under the “wwwroot” folder can be downloaded to the browser such as JavaScript and css files but also images and other downloadable files like .pdfs.
Advantages: Deployment and maintenance are easy – just copy the new/updated file(s) to the appropriate folder. You may need to stop/start IIS, depensing on which file you are working with.
Disadvantage: A disadvantage is it will be difficult to create reusable unit tests.
Razor Class Library
A Razor class library allows you to bundle reusable content in a library that can be used by more than one web application. During the project creation, you will be given a choice of what you want to store in the library.
NOTE: If you check the box, you will be given an “Area” folder that ultimately contains a “Pages” folder. Note the lack of a “wwwroot” folder in this instance.
NOTE: The decision of using a Razor library must be because of one of these reasons – maybe even for future projects. Depending on what you include will determine if it’s easy to test.
ASP.NET Core Empty
This “bare bones” project allows you to start from scratch. It’s a simpler template that grants you that freedom to add exactly what you will need. For example, maybe you want to create a website that just uses HTML, CSS, and JavaScript for now with the flexibility to add the framework items of your choice.
Disadvantage: A disadvantage would be that it requires the developer to know the patterns of what they are adding to the website. For example, if you are adding a controller and view, the developer must know where to create the folders and put the new files in the appropriate places. Also, Packages/References may need to be added as well. The other templates give you that guidance automatically.
ASP.NET Core Web App (Model-View-Controller)
Advantage: The biggest advantage of MVC is the testability, which is why many developers embraced and preferred it over WebForms at the time.
More Advantages: ASP.NET Core MVC looks a lot like .NET Framework MVC. This makes this framework an obvious choice when upgrading from an old ASP.NET MVC website to .NET Core.
Plus… The test projects will also upgrade nicely.
Disadvantage: A disadvantage would be the steeper learning curve for developers inexperienced with MVC. For those experienced, they should take the time to learn about the new features added with .NET Core (for example, View Components and Tag Helpers) and some features which were left behind in the old .NET Framework (like the Ajax Helper).
Blazor WebAssembly App
New with .NET 5+ is Blazor.
Two Models: The two models for it are WebAssembly (Wasm) for client-side Single Page Application (SPA) development and server-side Blazor for a classic request-response website (more on that model below).
Learn about wasm here: https://webassembly.org/
Today’s Web browsers now support a fourth API – Wasm, after HTML, CSS, and JavaScript. This API allows you to run binary code natively in the memory of the web browser. It still runs in a safety sandbox (like JavaScript) but can run much faster than interpreted JavaScript.
To create wasm code, it typically requires C++ or Rust. However, with Blazor, you can simply use C#. Your C# will be compiled to a .NET assembly that runs on Mono loaded into the browser and is then converted to wasm.
What Is A Blazor Wasm App? A Blazor Wasm app is a way to create a SPA that can easily call a web service or Representational State Transfer (REST) service. It uses the free ASP.NET Core SignalR library to make these calls.
Learn all about Blazor here: https://www.blazor.net/
PWA: The Progressive Web App (PWA) box will enable the web application to be installed locally into the web browser’s cache. It will also add a shortcut to the desktop and can run without Internet access if necessary. PWAs use custom APIs built into the web browser to cache information. They also make it easier to update the locally cached version of the application. Sadly, Firefox just stopped supporting PWAs this year.
Advantage: One big advantage of Blazor Wasm is that the developer spends most of their time writing C#, with very little JavaScript. This can be helpful if the developer/team has weak JavaScript skills.
Let’s not forget that ASP.NET Core (including Blazor) in general can run on Linux, iOS and Windows.
Blazor Server App
Advantage: An advantage of this type of project is that it can be easy to communicate with serves-side resources without exposing them to the Internet. For example, you can access a database server from this server-side code without the need to expose a REST service to the network/Internet. Granted, a disadvantage would be increased request/response communication with this model between click and server, but that can be more secure.
ASP.NET Core Web API
Web API (first introduced with MVC and the .NET Framework) is the preferred way to create REST APIs that can be accessed by any type of application, including desktop, web, mobile or even another REST service.
Typically, the data format used to send between an applications and Web API will be in JavaScript Object Notation (JSON) or Extensible Markup Language (XML) format. This allows the data to be compatible with all languages and platforms.
JSON is preferred for most SPA frameworks because it is smaller and more succinct. If top performance is important or a lot of data needs to be transmitted, then gRPC may be a better choice (coming up next).
When you create a Web API application, besides some of the normal options, you’ll be given a choice whether the project should include a Swagger API for testing the REST operations.
Web services were originally introduced with .NET 1 in 1998 which were then replaced by WCF in 2008 with .NET 3.5. However, WCF was much more fragile and fussy to work with. Also, it really didn’t work across different platforms unless you chose the classic web services API. Today, many .NET developers are rewriting WCF services into Web API or gRPC services for greater compatibility – especially with the latest SPA frameworks.
ASP.NET Core gRPC Service
gRPC lets you define four (4) kinds of service methods:
- unary(single) request/unary response
- unary request/stream response
- stream request/unary response
- stream request/stream response.
With streams, multiple pieces of data can be transmitted. gRPC even supports full duplex transmission (data can be sent/received simultaneously). The data types and methods are defined in a .proto file that is automatically compiled by Visual Studio using a protobuf compiler called “protoc”.
NOTE: Note how the method, the HelloRequest parameter, and the HelloResponse field are defined in the greet.proto file. If you highlight a type in “GreetService.cs” and click
The gRPC protocol was created by Google as open-source license under Apache 2.0. It’s already used by several large corporations for it speed, simplicity, and compatibility with almost all platforms and frameworks.
Check out the performance of gRPC vs. REST in this demo written using Go.
Learn more about the gRPC API standards, the docs, and try a tutorial here: (Click Here)
ASP.NET Core with Angular/React/React and Redux
Be aware that these templates may not be defined to use the latest version of the SPA frameworks (especially Angular, which has a new version released every six months).
As expected, the project includes a package.json file and a dedicated folder for storing your SPA framework called “ClientApp”.
When you build the .NET project, it will automatically also build your SPA framework. The first time you build it will require patience as it takes a while to compile.
Web Driver Test for Edge (Core/Framework)
Summary
Microsoft has changed the options quite a bit in the last few years, but know that .NET Framework projects are not going away.
Like the original Component Object Model (COM) architecture, the classic .NET Framework will continue to be supported for many years. However, for new development, you should probably consider using ASP.NET Core.
Best wishes, good luck and happy programming!
— Davin Mickelson
If You Work With A .NET Framework, Let Intertech Help You Pivot To ASP.NET Core.
Take a look at the proposed .NET Schedule .
.NET 5.0 Support And What You Should Know.
As you can see, Microsoft is changing its release strategy. .NET. 5.0 was released in 2021 and they will continue to release a new major version every year in November, beginning with .NET 6.0 in 2021 and .NET 7.0 in 2022. Microsoft is also changing its support strategy for .NET with Long Term Support (LTS) versions. Specifically, going forward, even-numbered version releases will be LTS versions with odd-numbered releases being General Availability (GA) releases. This new rapid release schedule can easily be overlooked by teams maintaining software solutions. It’s a significant shift in the release strategy for .NET by Microsoft. Software using the .NET framework will need to be updated to maintain security and performance.
If you are using .NET, speak with Intertech about complete application development & keeping your team up-to-date! Davin Mickelson & Intertech are ready to hear from you!