首页 > 代码库 > 001.Getting Started -- 【入门指南】

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


Getting Started

入门指南

662 of 756 people found this helpful

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

  • Building your first ASP.NET Core MVC app with Visual Studio
  • Your First ASP.NET Core Application on a Mac Using Visual Studio Code
  • Building Your First Web API with ASP.NET Core MVC and Visual Studio
  • Fundamentals

 

                                         蒙

                                    2016-09-27 11:50 周二

 

 

            支付宝打赏:                                    微信打赏:  

      技术分享              技术分享

 

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