651.288.7000 info@intertech.com

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?

ASP.NET Core? — Razor Pages? — MVC? — Blazor? — gRPC? — Web API?
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.”

 

For the screenshots I created below, I selected (circled in red) the “C#” language, “All platforms”, and just the “Web” project templates.

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

In the image below you will see the rest of the templates that are available to you!
One of the reasons I chose “All platforms” when filtering the project templates was to be sure I was using ASP.NET Core instead of the older .NET Framework. However, as shown above, some templates will still appear and be marked with “.NET Framework”.

Something To Remember

Microsoft offers us a link at the bottom (circled above) to find and install more templates from “Visual Studio Installer”.

Additional templates can be downloaded and installed from “Visual Studio Marketplace.”

Some of the choices shown above are project templates, control templates, components, tools, libraries and more. You can filter the results as you shop here.

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.

 

NOTE: I find it interesting that when I chose a “WCF Service Application” that it suddenly shows the “Windows” filter at the top.


Configure Your New Project

Take your time and choose wisely which version of .NET you want to use.

On Release of .NET 5 All “.NET Conf 2020” Presentations Were Published For Viewing.

Save This Link…

When Microsoft released the RTM versions of .NET 5 and EF Core 5, they held a live three day virtual conference called “.NET Conf” (November 10-12, 2020) at the virtual .NET Conf 2020.

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.


The even-numbered versions (6.0, 8.0, and so on) come with three years of Long-Term Support (LTS) from Microsoft while the odd-numbered versions (5.0, 7.0) only come with one year of LTS.


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

For example, you must be on .NET 3.x to use C# 7 while C# 8 will require .NET 5.x and C# 9 uses .NET 6.x.

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

Above is the default ASP.NET Core web project. It uses Razor pages, which are put underneath the “Pages” folder.

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.

By leaving the circled box above unchecked, you will be given a “wwwroot” folder and an example component that can interop with JavaScript.

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.

Advantages: The advantages of using a library are code reuse, greater consistency, simpler maintenance, and quicker deployment.

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.

Advantage: If you wanted to add Razor, MVC, WebAPI, Razor page – it’s all good! Very flexible and a great way to keep the website simple and elegant.

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)

Microsoft created the Model-View-Controller (MVC) model as an add-on for Visual Studio 2008 with the .NET Framework.

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/

When you are creating the project, you will have a couple of checkboxes. The first enables complementary server-side code that can be used with your client-side code.

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.

A Blazor web app has a “wwwroot” folder and a “Pages” folder. The Razor files can easily be mistaken for Razer pages because of the .razor file extension. However, they are Razor components. If you recall, Razer pages end with .cshtml.

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

A Blazor Server app obviously runs on the web server. It can still be used with a SPA framework (Angular, ReactJS, ViueJS) if needed. Since it runs on the server, it typically will post back to the server for every click event by the user – unless a SPA framework is used.
These apps also use Razer components in the “Pages” folder. As you can see above, they can also be mixed with Razer pages. The “Data” folder can hold reusable classes and ASP.NET Core services.

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.

When selected, you can see how it will be added to the “Packages” folder and registered in the “Startup” class.
Swashbuckle is a package that you can use in your .NET Web API projects. Its purpose is to generate the Swagger spec for your project. The Swagger UI is contained within Swashbuckle. Swagger UI displays the documentation. It uses Swashbuckle to do this.

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

If you are creating a new REST service hosted on the cloud or one that will be connected to by many mobile devices and top performance is important, you should seriously consider gRPC (Google Remote Procedure Call) instead of Web API.

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”.

This is the sample code initially created with this project.

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 to go to the definition, it will generate temporary code representing what is normally created by protoc.

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

These project templates assume you want to create a SPA application with an ASP.NET Core back end.

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”.

It has a sample Web API controller for a back-end REST service and a “Pages” folder for Razor pages (if wanted).

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)

This last project shows how you can use the Microsoft Driver with Selenium or some other third-party driver to automate user testing for the Chromium-based Microsoft Edge. It simulates a user sitting at a computer interacting with your website.
In this screen shot you can see that the project includes the MSTest packages, the legendary Selenium library, and a test script.

Summary

Our intent with this document is to help you better understand your choices for selecting and creating a new ASP.NET project.

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.

It’s easy to delay adopting new technologies, even when the stakes are high. In so many cases, the energy is spent improving business strategies (building more widgets, increasing quality, refining services). At the same time, technology updates take a back seat when it comes to corporate reinvestment, even when security is a priority, and using older technology is often the weak link in performance.

 

Take a look at the proposed .NET Schedule .

 

w

.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!

Discover All That Intertech Can Do For You!

Let’s Build Something Great!

Tell us what you need and we’ll get back with you ASAP!
Consider Intertech…

Tell us about your project and we’ll gather the right people, discuss your request, clarify any questions, and provide a price estimate that you can use to decide if Intertech is a good fit for you!

“We Take The Worry Out Of Custom Software Development!”

Turn-Key Custom Application Development Solutions Since 1991

Independent & Co-Development

Tom Salonek Founder & CEO