For this article I decided that it would be appropriate to show off the process of installing and creating an ASP.NET Core MVC project on macOS. Also I will explain what you have to do differently when creating a web project instead of a console application.
Microsoft’s ASP.NET Core website explains the installation part thoroughly. Nevertheless, here I prepared a short summary of what you have to perform prior to running the project.
- Install Homebrew (if not already present on your machine)
- Follow steps 1 and 2 as described on Microsoft’s .NET Core website
- Enter the first two commands of step 3
- mkdir <dirName> – creates a new directory with a name of <dirName>
- cd <dirName> – mounts the <dirName> directory
Now since this article is about ASP.NET Core MVC you shall not follow the whole third step, because it advises to use dotnet new. This would, by default, create a .NET Core Hello World console application and it’s respective project structure. Instead, enter dotnet new -t web into the Terminal window.
After the command is executed you may proceed to step 4 ( dotnet restore — which will restore NuGet packages for the project and ensure that installed packages and it’s versions comply to those of the project.json file int the root folder — and dotnet run which will start serving the project under http://localhost:5000).
Testing YOUR Project
If you now navigate to the above-mentioned localhost URL in your browser, you are presented with a default ASP.NET page known for many years as part of ASP.NET MVC.
Working with the project
At this point you can edit each file of your project as you like. When the page gets refreshed, all changes will be applied instantly — without the need to run dotnet run in your Terminal window — and seen in your browser window.
I myself have struggled to create web application instead of a console application when it came to .NET Core CLI. Now I hope the process has been properly explained. However, if you ever get lost, feel free to use the dotnet --help command. From there you will sure get to the bottom of your problem.