.NET Core 1.0-最简单的Hello world控制台程序

时间:2022-05-31 21:49:29


使用任意的文本编辑软件,新建两个文件

1.Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; namespace TestNuGetConsole
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello from DNX!");
}
}
}

2.project.json

{
"version": "1.0.0-*",
"description": "TestNuGetConsole Console Application",
"authors": [ "eric" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "", "compilationOptions": {
"emitEntryPoint": true
}, "dependencies": {
}, "commands": {
"TestNuGetConsole": "TestNuGetConsole"
}, "frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Console": "4.0.0-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
}

Windows环境下

窗口+R,输入cmd,然后使用cd命令进入文件所在目录。

执行命令:dnu restore

.NET Core 1.0-最简单的Hello world控制台程序

等待下载包,执行成功的提示

.NET Core 1.0-最简单的Hello world控制台程序

执行命令:dnx run

.NET Core 1.0-最简单的Hello world控制台程序

成功完成!

CentOS环境下

基本与WIndows下一样

执行命令:dnu resotre

.NET Core 1.0-最简单的Hello world控制台程序

执行命令:dnx run

.NET Core 1.0-最简单的Hello world控制台程序