Search⌘ K
AI Features

Getting Started with SignalR

Explore how to set up a SignalR project from scratch by creating folders, generating a solution, and adding an ASP.NET Core MVC SignalR server project. Understand the initial commands and project structure needed to start real-time web development with SignalR.

Setting up the SignalR server

Let's see how we can set up our SignalR server.

A server
A server

After clicking on the terminal given below, perform the following steps:

Step 1: Create a folder

Create a folder having the name LearningSignalR by executing the given command.

 mkdir LearningSignalR

Step 2: Navigate to the folder

Navigate to this newly created folder using the following command:

cd LearningSignalR

Step 3: Generate the solution

Now, execute the following command inside the LearningSignalR folder:

dotnet new sln

This command is expected to generate a solution file with the same name as the folder. So, in our case, to ensure that the command has worked, we need to check whether our folder contains LearningSignalR.sln file.

Step 4: Generate the SignalR project

Now, we’ll instantiate a project based on the ASP.NET Core MVC template. To do so, while having the terminal open in the solution folder, we’ll execute the following command:

dotnet new mvc  -o SignalRServer

This command will generate the SignalRServer folder inside the solution folder with the default code setup for the ASP.NET Core MVC project.

Step 5: Add the project

We’ll now need to add the project to the solution. And to do so, this is the command we’ll need to execute:

dotnet sln add SignalRServer/SignalRServer.csproj

The right-most argument of this command is the relative path to the C# project file, which has the csproj extension.

That’s it. We now have a solution with an MVC project in it. So, we can use the nano command to open the sln file. Now, we’re ready to add SignalR components to our project.

Note: Since the environment is pre-established on the Educative platform, you don’t need to do any installation. We’ll work on Ubuntu 20.04.4 LTS throughout the course.

Terminal 1
Terminal
Loading...

This is how your output on the terminal should look:

The project has been added to the solution
The project has been added to the solution