mac .net core尝试

以下是对.net core 发布的尝试,内容完全来自微软官方的文档粘贴,主要是用来记录尝试的过程。

下载

https://www.microsoft.com/net/download

.NET Core SDK = Develop apps with .NET Core and the SDK+CLI (Software Development Kit/Command Line Interface) tools
.NET Core = Run apps with the .NET Core runtime

安装 SDK

macOS 10.11 (El Capitan) or higher is required. There are known issues with OpenSSL 0.9.8 and oh-my-zsh

https://github.com/dotnet/core/blob/master/cli/known-issues.md

安装完后提示

1
2
3
$dotnet --help
zsh: command not found: dotnet

创建链接

1
2
ln -s /usr/local/share/dotnet/dotnet /usr/local/bin

再次执行

1
2
3
4
5
$dotnet --help
.NET Command Line Tools (1.0.0-preview2-003121)
......


具体的步骤参考 https://www.microsoft.com/net/core#macos

创建项目

1
2
3
4
mkdir hwapp
cd hwapp
dotnet new

运行项目

1
2
3
dotnet restore
dotnet run

创建 website 入门

https://docs.asp.net/en/latest/getting-started.html

Install .NET Core

Create a new .NET Core project:

1
2
3
4
mkdir aspnetcoreapp
cd aspnetcoreapp
dotnet new

Update the project.json file to add the Kestrel HTTP server package as a dependency:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
},
"frameworks": {
"netcoreapp1.0": { }
}
}

Restore the packages:

1
2
dotnet restore

Add a Startup.cs file that defines the request handling logic:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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!");
});
}
}
}

Update the code in Program.cs to setup and start the Web host:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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();
}
}
}

Run the app (the dotnet run command will build the app when it’s out of date):

1
2
dotnet run

###Browse to http://localhost:5000:

作者

张巍

发布于

2016-07-05

更新于

2016-07-05

许可协议

评论