Creating your first ASP.NET Core 3 application via the command line

In the previous section, you learned how to create your first ASP.NET Core 3 web application with Visual Studio 2019. This should be the preferred method for most developers.

However, if you prefer using the command line or Visual Studio Code, which we are going to introduce a little later on in this book, then using Visual Studio 2019 is not really an option. Luckily, .NET Core and ASP.NET Core 3 provide full support for the command line. This may even be your only option on other operating systems such as Linux or macOS. The same command-line instructions work on all the different operating systems, so once you get used to them, you can work on any environment.

Now, let's learn how to create our first sample application using the Windows command line:

  1. If you haven't installed the .NET Core 3 SDK yet, then download and install .NET Core 3 from https://dotnet.microsoft.com/download/dotnet-core/3.0.
  2. Create a folder for your sample application called mkdir aspnetcoresample.
  3. Move into the new folder: cd aspnetcoresample.
  4. Create a new web application based on the empty ASP.NET Core 3 web application template called dotnet new web.
Previous versions of .NET Core required an additional -t parameter for choosing a template (dotnet new -t web). If you get an error when executing dotnet new web, it is a good indication that you need to install .NET Core 2.0.

Note that you can verify your .NET version by entering dotnet (with no parameters) if you are not sure about your environment since it will display the current .NET Core version.

  1. Run the sample application by executing dotnet run:
  1. Open a browser and go to http://localhost:5000. If everything worked correctly, you should see a Hello World! page:

In this section, you've learned how to create your first sample application by using Visual Studio 2019 or the command line, and you learned how to use Visual Studio Code and how it helps you when building an ASP.NET Core 3 application on Linux or macOS.

Now that you have installed Visual Studio 2019 and have your first application up and running, you need to know what to do when you encounter errors in your application. This is a matter of when, not if. Do not despair if you do get errors when developing applications – this happens even to the most experienced. Luckily, Visual Studio helps us to diagnose errors. We will look at debugging with Visual Studio 2019 in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.235.119