DotNet Core 1.0 集成 CentOS 开发与运行环境部署

时间:2021-06-26 22:11:26

一、     DotNet Core 1.0 开发环境部署

  1. 操作系统安装

我们使用CentOS 7.2.1511版本.

DotNet Core 1.0 集成 CentOS 开发与运行环境部署

  1. 安装libunwind库

执行:sudo yum install libunwind libicu

libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,32位操作系统不要安装。其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API。.

  1. 下载DotNet安装包

执行:curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131

DotNet安装包提供了linux下的编译环境

DotNet Core 1.0 集成 CentOS 开发与运行环境部署

  1. 解压安装包

执行:sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet

  1. 创建文件链接

执行:sudo ln -s /opt/dotnet/dotnet /usr/local/bin

二、     创建代码文件结构

  1. 创建代码目录

执行:mkdir hwapp

  1. 创建代码文件

执行:cd hwapp

dotnet new

执行完后,代码目录中多了两个文件:Program.cs、project.json

DotNet Core 1.0 集成 CentOS 开发与运行环境部署

三、     编码

  1. Program.cs
using System;
using Microsoft.AspNetCore.Hosting; namespace aspnetcoreapp
{
public class Program
{
public static void Main(string[] args)
{ var host = new WebHostBuilder()
.UseUrls("http://*:1000", "https://*:1234", "http://0.0.0.0:5000")
.UseKestrel()
.UseStartup<Startup>()
.Build(); host.Run();
}
}
}

2.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 World");
});
}
}
}

3.project.json

{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": { },
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
},
"imports": "dnxcore50"
}
}
}

四、     编译与运行

  1. 编译

执行:dotnet restore

DotNet Core 1.0 集成 CentOS 开发与运行环境部署

  1. 运行

执行:dotnet run

DotNet Core 1.0 集成 CentOS 开发与运行环境部署

Kestrel  Web服务器开启了5000端口,可以通过浏览器访问服务器的5000端口

DotNet Core 1.0 集成 CentOS 开发与运行环境部署