001.Getting Started -- 【入门指南】



索引:

目录索引

Getting Started

入门指南

 

Meng.Net 自译

1. Install .NET Core

 到官网安装 .NET Core

2. Create a new .NET Core project:

 用cmd命令窗口 ,创建一个新的 工程

  mkdir aspnetcoreapp

  新建目录 aspnetcoreapp

  cd aspnetcoreapp

  移动到目录  aspnetcoreapp

  dotnet new

  在目录中新建工程

3. Update the project.json file to add the Kestrel HTTP server package as a dependency:

  更新 project.json 文件,添加 Microsoft.AspNetCore.Server.Kestrel 依赖包

 1 {
 2   "version": "1.0.0-*",
 3   "buildOptions": {
 4     "debugType": "portable",
 5     "emitEntryPoint": true
 6   },
 7   "dependencies": {},
 8   "frameworks": {
 9     "netcoreapp1.0": {
10       "dependencies": {
11         "Microsoft.NETCore.App": {
12           "type": "platform",
13           "version": "1.0.0"
14         },
15         "Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
16       },
17       "imports": "dnxcore50"
18     }
19   }
20 }
project.json

4. Restore the packages:

  使用 nuget 更新依赖文件

  dotnet restore

  更新依赖文件命令

5. Add a Startup.cs file that defines the request handling logic:

  添加 Startup.cs 文件,定义请求处理逻辑

 1 using System;
 2 using Microsoft.AspNetCore.Builder;
 3 using Microsoft.AspNetCore.Hosting;
 4 using Microsoft.AspNetCore.Http;
 5 
 6 namespace aspnetcoreapp
 7 {
 8     public class Startup
 9     {
10         public void Configure(IApplicationBuilder app)
11         {
12             app.Run(context =>
13             {
14                 return context.Response.WriteAsync("Hello from ASP.NET Core!");
15             });
16         }
17     }
18 }
Startup.cs

6. Update the code in Program.cs to setup and start the Web host:

  更新 Program.cs 文件,设置并启动 Web host :

 1 using System;
 2 using Microsoft.AspNetCore.Hosting;
 3 
 4 namespace aspnetcoreapp
 5 {
 6     public class Program
 7     {
 8         public static void Main(string[] args)
 9         {
10             var host = new WebHostBuilder()
11                 .UseKestrel()
12                 .UseStartup<Startup>()
13                 .Build();
14 
15             host.Run();
16         }
17     }
18 }
Program.cs

7. Run the app (the dotnet run command will build the app when it’s out of date):

  运行程序

  dotnet run

  运行程序命令

8. Browse to http://localhost:5000:

  在浏览器中浏览

  

Next steps


 

                                         蒙

                                    2016-09-27 11:50 周二

         

                    

原文地址:https://www.cnblogs.com/Meng-NET/p/5912293.html