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

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.

主站蜘蛛池模板: 泰顺县| 都江堰市| 通榆县| 民和| 民县| 托里县| 安福县| 永仁县| 交城县| 丰城市| 株洲市| 黔西| 饶河县| 杭锦后旗| 桂东县| 剑河县| 海原县| 镇赉县| 连山| 广平县| 哈密市| 东源县| 江津市| 邻水| 清新县| 台州市| 扎赉特旗| 青川县| 彰化县| 重庆市| 闸北区| 忻城县| 延寿县| 绥中县| 昭平县| 东丽区| 德庆县| 汾阳市| 宜章县| 积石山| 将乐县|