You can use the .NET Command Line Interface (CLI) to create, build and run a new ASP.NET application.
Navigate to the folder where you want to create your project.
Execute the following command:
dotnet new mvc -o
This will create a folder with the same name as your project and will create inside that folder a project with that name and the .csproj extension. It will also create some subfolders and boilerplate code.
For example, if I issue the command:
dotnet new mvc -o mymvc
It will create a folder named "mymvc" and an ASP.NET MVC project inside that folder. By default, the project will have the same name as the folder. You can assign a different name using the "-n" argument, as in the following example:
dotnet new mvc -n myaspnetmvc -o mymvc
Navigate to this folder (
cd mymvc) and view the contents (
You will see something like the Fig. 1.
Fig. 2 shows the files in the Visual Studio Code Explorer with some of the folders expanded to reveal the files within.
The new application is configured to use HTTPS, which requires a trusted certificate. This can be a problem when running the application locally. Fortunately, you can execute the following command to tell ASP.NET to trust the certificate on your local machine.
dotnet dev-certs https --trust
The first time you run the command, a confirmation dialogue displays. Click YES to confirm if prompted.
Execute the following command from the project folder to build the ASP.NET application.
Execute the following command from the project folder to run the ASP.NET application locally.
NOTE: The last command will also build the project if any code file has changed since the last build.
When you run an ASP.NET application locally, it displays the URL of the default page, as in Fig. 3.
In the example above, the application is at http://localhost:5076. You may open a browser and navigate to this URL or hold down the CTRL key and click the link. Fig. 4 shows the default page in a browser.
To terminate the application, press CTRL+C in the command window.
In this article, you learned how to use the .NET Command Line Interface (CLI) to create, build and run a new ASP.NET application.