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



索引:html

目錄索引web

Getting Startedjson

入門指南api

 

Meng.Net 自譯瀏覽器

1. Install .NET Coremvc

 到官網安裝 .NET Coreapp

2. Create a new .NET Core project:asp.net

 用cmd命令窗口 ,建立一個新的 工程ide

  mkdir aspnetcoreappui

  新建目錄 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 週二

相關文章
相關標籤/搜索