tipos-de-proyectos-aspnet-core

Types of Projects in ASP.NET

  • 7 min

When you start in the world of ASP.NET, one of the first things you will encounter is that there are different types of projects that we can choose from, depending on our needs.

In fact, it is one of the most confusing things at first because there are a huge number of options, and it’s easy to get lost among so many choices.

So let’s take a look at the main projects in ASP.NET, their features, and when it is most appropriate to use each one.

Here is a summary of the different types of ASP.NET projects that you will encounter.

CommandProject TypeDescription
dotnet new webEmptyCreates an empty project
dotnet new webapi✅ RESTful APICreates an API that follows RESTful style for web services
dotnet new mvc❌ MVCCreates an application with the Model-View-Controller pattern
dotnet new razor❌ Razor PagesCreates a project with Razor Pages
dotnet new blazorwasmBlazor WebAssemblyCreates a Blazor client application with WebAssembly.
dotnet new blazorserverBlazor ServerCreates a Blazor Server application

Not all are equally useful, nor used (not even remotely), and some of them are maintained for compatibility. Currently, the ones you will use most frequently are:

  • ✅ RESTful API: For almost everything
  • Blazor: If you want to develop in this technology
  • Empty Project: For a quick test (or to start from scratch)

But if you want more information about all of them, here it is so you can get to know them and know when it’s appropriate to use them (or not) 👇

Creates an empty project without any predefined structure. This is useful if you want to create a completely custom application or if you need full control over the project configuration.

To create an empty project, simply run:

dotnet new web -n MyEmptyProject

This will generate an empty project where you can add what you need: controllers, views, static files, services, among others.

Generates a RESTful API that follows HTTP conventions, using JSON as the data interchange format.

This type of project is common for exposing backend services, where a graphical interface is not necessary, but endpoints are provided that can be consumed by frontend or mobile applications.

To create an API project, use the following command:

dotnet new webapi -n MyApi

When to use it:

  • Web Services: If you are developing a backend that will be consumed by different clients.
  • Microservices: If you are building a microservices architecture, each service can be a RESTful API.
  • SPA Applications: APIs + SPA frontends (React, Angular, Blazor).

Creates a project based on the Model-View-Controller (MVC) pattern. This pattern divides the application into three main components:

  • Model (Model): Represents the data and business logic.
  • View (View): Represents the graphical interface of the application.
  • Controller (Controller): Acts as an intermediary between the model and the view.

To create a new MVC application, open the console and run the following command:

dotnet new mvc -n MyApplicationName

When to use it:

  • It has been the classic for years.
  • Nowadays, it is not used as much except in existing applications (legacy)

Razor Pages was released with .NET Core 2.0 (2017), promoted by Microsoft as a simpler alternative to MVC. Unlike MVC, a strict separation of controllers and views is not required.

However, it did not achieve great popularity, except in internal projects, administrative forms, or environments where something very simple is sought without using SPA (React, Angular, Blazor).

To create a project with Razor Pages, run:

dotnet new razor -n MyRazorPageApp

When to use it:

  • ⛔If you are threatened with a gun and have no other choice(and even then I would consider it)

Blazor is a web application development framework that allows you to create interactive applications using C# instead of JavaScript.

Blazor can run on the server (Blazor Server) or on the client (Blazor WebAssembly).

dotnet new blazorserver -n MyBlazorApplication

This command will create a new Blazor Server project with the basic structure of folders and files needed.

When to use it:

  • Interactive Applications: If you are developing a web application that requires high user interactivity.
  • Single Page Applications (SPA): If you are building a single-page application (SPA) and prefer to use C# instead of JavaScript.

Common Use Cases

We have seen the types of projects that ASP.NET offers. These are the “real project types.” When we create a project we will have to choose a type and we cannot change it.

But do not confuse the “project type” of ASP.NET with what we can do with this project (use cases)

We have already seen that the most powerful and versatile project type is RESTful API. But this does not mean we can only create APIs with it.

So let’s look at the “use cases” that we can perform with ASP.NET, either alone or with other technologies 👇.