在 Arch Linux 中使用 .NET Core SDK

黃志斌發表於2018-03-18

安裝 .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

相關文章