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

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.

主站蜘蛛池模板: 宝坻区| 泰安市| 衡山县| 大余县| 华宁县| 皮山县| 丰原市| 宁晋县| 墨江| 司法| 若羌县| 威信县| 桂东县| 翁牛特旗| 金湖县| 桦甸市| 收藏| 保定市| 康乐县| 保亭| 夹江县| 泸溪县| 明水县| 耿马| 错那县| 将乐县| 鄂伦春自治旗| 宝应县| 松滋市| 宜兴市| 环江| 南丰县| 吉木乃县| 新化县| 孙吴县| 南丹县| 洛浦县| 丽水市| 和政县| 鄄城县| 达孜县|