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

Creating your first app

Run the following command to create a new console app from a template:

dotnet new console -o DotNetCoreTwoHelloWorld

Then switch to the directory that was just created and run it with these two commands:

cd DotNetCoreTwoHelloWorld

dotnet run

Your console should look something like the following screenshot (if you're using PuTTY on Windows):

With .NET Core 1.0, you needed to call dotnet restore before building or running your application with the dotnet command. In .NET Core 2.0, this is called on your behalf for dotnet commands that require it, and you no longer need to restore NuGet packages manually this way.

Assuming that the basic console application worked, let's create a web app. Run the following commands to move up a level to the parent folder and list the templates:

cd ..

dotnet new

Without any additional parameters, the dotnet new command will list all the available templates. These are shown in the following screenshot:

Let's make a standard MVC web app like we did in our other previous examples. The next three commands will create a new web app from a template, switch to the folder created, and run the app:

dotnet new mvc -o AspNetCoreTwoMvc

cd AspNetCoreTwoMvc

dotnet run &

We're executing the app in the background (with &) so that we can use the terminal while it is still running. You could connect to your server with a browser on your local machine, but this would require binding the web server to the external IP address and opening ports on the server and cloud firewalls.

Let's very simply test whether our web server is working by downloading the home page with the following command. If you don't have wget installed, then you could use curl instead:

wget localhost:5000

This process is shown in the following screenshot:

We can view the source of the home page with a command-line text editor, like so:

nano index.html

You will now see the HTML source of the default home page, as shown here:

To tidy up, we should end the dotnet process that is still running. You can use the kill command to end the process with the ID shown when you started it. If you can't find the ID, then you can use ps x to list the processes that are running.

主站蜘蛛池模板: 合阳县| 滨海县| 武隆县| 安宁市| 分宜县| 呼伦贝尔市| 德江县| 鸡西市| 黑水县| 阜平县| 东山县| 治多县| 哈尔滨市| 新和县| 南通市| 措美县| 旅游| 屯留县| 仙居县| 隆安县| 五指山市| 谢通门县| 柳州市| 沈丘县| 十堰市| 宜都市| 遵义县| 庆阳市| 门源| 循化| 宕昌县| 广安市| 重庆市| 钦州市| 许昌市| 新郑市| 东丽区| 石楼县| 孟连| 香格里拉县| 清丰县|