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

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.

主站蜘蛛池模板: 堆龙德庆县| 泌阳县| 闻喜县| 灌阳县| 治多县| 章丘市| 洪泽县| 都江堰市| 色达县| 邢台市| 岳池县| 绥棱县| 吴桥县| 仪陇县| 塔河县| 香河县| 武鸣县| 五寨县| 灵川县| 新巴尔虎右旗| 禹州市| 木兰县| 剑河县| 达拉特旗| 平远县| 商河县| 盐边县| 富锦市| 衡南县| 柘荣县| 龙门县| 丹巴县| 当雄县| 迁安市| 扎赉特旗| 法库县| 晋州市| 凤山市| 潞西市| 桓台县| 浦县|