安装 .NET Core SDK

安装:

$ sudo pacman -S dotnet-sdk

查看版本信息:

$ dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   2.1.301
 Commit:    59524873d6

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /opt/dotnet/sdk/2.1.301/

Host (useful for support):
  Version: 2.1.1
  Commit:  6985b9f684

.NET Core SDKs installed:
  2.1.301 [/opt/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.NETCore.App 2.1.1 [/opt/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

我的第一个 .NET Core 程序

$ cd src/dotnet
$ dotnet new console -o clrversion

The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on clrversion/clrversion.csproj...
  Restoring packages for /home/ben/src/dotnet/clrversion/clrversion.csproj...
  Generating MSBuild file /home/ben/src/dotnet/clrversion/obj/clrversion.csproj.nuget.g.props.
  Generating MSBuild file /home/ben/src/dotnet/clrversion/obj/clrversion.csproj.nuget.g.targets.
  Restore completed in 273.53 ms for /home/ben/src/dotnet/clrversion/clrversion.csproj.

Restore succeeded.

$ cd clrversion
$ dotnet run
Hello World!

将 Program.cs 中 Main 函数的内容改为:

Console.WriteLine("OS : " + Environment.OSVersion);
Console.WriteLine("CLR: " + Environment.Version);

再次运行:

$ dotnet run
OS : Unix 4.17.3.1
CLR: 4.0.30319.42000

参考资料

  1. ArchWiki: .NET Core
  2. Microsoft: Get started with .NET in 10 minutes
  3. Microsoft: .NET Core 指南
  4. Issue #3845: dotnet CLI crashing on Arch Linux