运行第一个.net core程序

前置条件 ubuntu已安装.net core运行环境

分6步

mkdir netcore 创建一个项目文件夹

cd netcore   进入该文件夹

dotnet new  new命令 用于创建一个新的控制台应用程序

 dotnet restore  分析 project.json 文件, 下载依赖并返回结果

dotnet build  编译项目

dotnet run  运行项目

root@ubuntu:~/firstnetcore# mkdir netcore
root@ubuntu:~/firstnetcore# cd netcore
root@ubuntu:~/firstnetcore/netcore# dotnet new
Created new C# project in /root/firstnetcore/netcore.
root@ubuntu:~/firstnetcore/netcore# ls
Program.cs project.json
root@ubuntu:~/firstnetcore/netcore# dotnet restore
log : Restoring packages for /root/firstnetcore/netcore/project.json...
log : Writing lock file to disk. Path: /root/firstnetcore/netcore/project.lock.json
log : /root/firstnetcore/netcore/project.json
log : Restore completed in 2336ms.
root@ubuntu:~/firstnetcore/netcore# dotnet build
Project netcore (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling netcore for .NETCoreApp,Version=v1.0

Compilation succeeded.
0 Warning(s)
0 Error(s)

Time elapsed 00:00:00.8093903

root@ubuntu:~/firstnetcore/netcore# dotnet run
Project netcore (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
Hello World!
root@ubuntu:~/firstnetcore/netcore#

运行效果

原文地址:https://www.cnblogs.com/ProDoctor/p/7605823.html