This video is available to students only

Creating WebAPI Project using DOTNET CLI

In this lesson, we'll create our DOT NET web Api project using the DOTNET CLI.

Creating WebAPI project using DOTNET CLI#

Did you know? 📣 In Dot Net, you can have multiple versions of SDK and Runtimes installed simultaneously

Finally, it's about time we started working on the project. First of all, open the terminal and check if Dot Net SDK is currently installed.

Use the command:

Now, the latest version I have is 5.0.201. It can be different when you're watching it. As you can see, I have multiple versions of SDK and runtimes and as we discussed before, we can have multiple versions running simultaneously. If you're confused about the difference between SDK and a runtime; SDK is a software development kit which includes stuff you need to build and run the application, such as the CLI and the compiler, whereas, runtime helps to run the apps which are already complied with the SDK. I hope this makes sense.

Don't worry if version 6 is out and it becomes the latest version. Most probably, the changes won't be breaking and if there are such, I will make appropriate changes to the course.

If you see version 6 as the current version, please switch to version 5 to now by running this command

Now that the software development kit is correctly installed, type dotnet -h to check all the available commands. Out of these commands, new helps us to create a new project or a new file, run will build and run the application, sln command will create a solution file, and watch command will start a file watcher which will keep our server ready with the changes so we won't have to restart the server again and again.

Use the command to check the available options:

Now what we'll do is clear the terminal, type dotnet new -l and enter. This will give us a list of templates available to us to create dotnet related projects or files. Out of these options, we will first create a solution file using the sln command. Solution file works as a container for the application's project. If you are using VS Code, then the solution file helps to build all those projects which are part of solution just by running dotnet build command. We'll also be creating Web API project. This will be the starter project which will actually run our application.

We'll also be using the classlib command, which helps to connect other projects to our Web API. For example, if you want to create a different project that takes care of the data and interacts with the database, you can create a class library and later on add a reference to the main project.

Now that you know all the available commands, go to the directory where you want to store your project. I will create it in my desktop. Type mkdir learnify and then, cd learnify. Once you're inside the project, create a new solution file using dotnet new sln and press enter.

Start a new discussion. All notification go to the author.