原文:Getting Started
翻译:娄宇(Lyrics)
校对:刘怡(AlexLEWIS)
1、安装 .NET Core
2、创建一个新的 .NET Core 项目:
mkdir aspnetcoreappcd aspnetcoreapp
dotnet new
3、编辑 project.json 文件,添加 Kestrel HTTP server 包引用:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002702"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
4、还原包:
dotnet restore
5、添加一个 Startup.cs 文件并定义请求处理逻辑:
using System;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.Http;namespace aspnetcoreapp{ public class Startup
{ public void Configure(IApplicationBuilder app) {
app.Run(context =>
{ return context.Response.WriteAsync("Hello from ASP.NET Core!");
});
}
}
}
6、编辑 Program.cs 中的代码来设置和启动 Web 宿主:
using System;using Microsoft.AspNetCore.Hosting;namespace aspnetcoreapp{ public class Program
{ public static void Main(string[] args) { var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
7、运行应用程序(dotnet run
命令会在应用程序过期时构建它):
dotnet run
8、浏览http://localhost:5000
:
DEMO 代码(https://github.com/aspnet/Docs/tree/master/aspnet/getting-started/sample/aspnetcoreapp)
下一步
用 Visual Studio 创建 ASP.NET Core MVC 应用程序
用 Visual Studio Code 在 macOS 上创建首个 ASP.NET Core 应用程序
用 Visual Studio 和 ASP.NET Core MVC 创建首个 Web API
原理
相关文章:
原文地址:http://www.cnblogs.com/dotNETCoreSG/p/aspnetcore-1-getting_started.html
.NET社区新闻,深度好文,微信中搜索dotNET跨平台或扫描二维码关注