使用 .NET Core 创建新程序
首先通过你选择的平台的安装说明安装 .NET Core SDK :
安装完成后,打开命令提示符或终端窗口。
-
使用
mkdir hello_world创建一个新目录,然后使用cd hello_world切换到新创建的目录。 -
使用
dotnet new console创建一个新的控制台应用程序。
这将产生两个文件:-
hello_world.csproj
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> </Project> -
Program.cs 中
using System; namespace hello_world { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
-
-
使用
dotnet restore恢复所需的包。 -
可选使用
dotnet buildfor Debug 或dotnet build -c Releasefor Release 构建应用程序。dotnet run还将运行编译器并抛出构建错误(如果找到)。 -
使用
dotnet runfor Debug 或dotnet run .\bin\Release\netcoreapp1.1\hello_world.dllfor Release 运行应用程序。
命令提示输出
