1、创建一个新.NET Core 项目
mkdir aspnetcoreapp
cd aspnetcoreapp
dotnet new
更新project.json文件添加Kestrel HTTP server依赖包
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
<span style="background-color: rgb(255, 102, 102);">"Microsoft.AspNetCore.Server.Kestrel": "1.0.0"</span>
},
"imports": "dnxcore50"
}
}
}
2、还原包
dotnet restore
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!");
});
}
}
}
4、更新Program.cs
using System;
namespace <span style="color: rgb(85, 85, 85); font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Liberation Mono', 'Nimbus Mono L', Monaco, 'Courier New', Courier, monospace; line-height: 18px; white-space: pre; background-color: rgb(255, 255, 204);">aspnetcoreapp</span>
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}<strong>
</strong>
5、运行与浏览dotnet run
http://localhost:5000