官术网_书友最值得收藏!

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

In the previous section, you saw how to create your first ASP.NET Core 2.0 sample application with Visual Studio 2017, and this should be the preferred method for most common developers.

However, if you prefer using the command line or Visual Studio Code, which we are going to introduce a little later in the book, then using Visual Studio 2017 is not really an option. Luckily, .NET Core and ASP.NET Core 2.0 provide full support for the command line. This might 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.

Let's see now how creating your first sample application using the Windows command line works:

  1. If the .NET Core 2.0 SDK is not yet installed, then download and install .NET Core Preview 2 from https://www.microsoft.com/net/core/preview.

Note that this step might no longer be needed at the time of reading this book,  since it should have been released officially by then.

  1. Create a folder for your sample application, mkdir aspnetcoresample.
  2. Move into the created folder, cd aspnetcoresample.
  3. Create a new web application based on the empty ASP.NET Core 2.0 web application template, dotnet new web.

Previous versions of .NET Core required an additional -t parameter for choosing the 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:

You have seen how to create your first sample application either by using Visual Studio 2017 or the command line. You will now see how to use Visual Studio Code and how it helps you when building an ASP.NET Core 2.0 application on Linux or macOS.

主站蜘蛛池模板: 大悟县| 德庆县| 波密县| 盘山县| 福贡县| 潢川县| 永和县| 安龙县| 上虞市| 萨迦县| 崇文区| 洛宁县| 台湾省| 丰台区| 榆林市| 乌鲁木齐县| 姜堰市| 太康县| 江源县| 陵川县| 滨海县| 涿鹿县| 静乐县| 天镇县| 阿克苏市| 宿松县| 吐鲁番市| 资中县| 全州县| 德州市| 静乐县| 云浮市| 镇赉县| 双桥区| 维西| 安康市| 龙南县| 勃利县| 麟游县| 亳州市| 都江堰市|