CentOS之.NET CORE-开始

前端之家收集整理的这篇文章主要介绍了CentOS之.NET CORE-开始前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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


3、添加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!");
            });
        }
    }
}

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

猜你在找的.NET Core相关文章