LoginSignup
13
14

More than 1 year has passed since last update.

Linux で .Net 6 を使う

Last updated at Posted at 2018-03-07

次のページを参考にしました。
Windows/Linux/macOS の .NET Core でのコマンド ラインの使用に関する概要

Arch Linux でのインストール方法

sudo pacman -S dotnet-sdk

インストール後に

sudo chmod 777 /opt/dotnet/sdk

Ubuntu 22.04 でのインストール方法

sudo apt install dotnet6

バージョンの確認

$ dotnet --version
6.0.109

サンプルのプログラムの作成

mkdir example
cd example
dotnet new console

次のファイルが作成されます。

$ tree
.
├── Program.cs
├── example.csproj
└── obj
    ├── example.csproj.nuget.dgspec.json
    ├── example.csproj.nuget.g.props
    ├── example.csproj.nuget.g.targets
    ├── project.assets.json
    └── project.nuget.cache

1 directory, 7 files
Program.cs
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

実行

 $ dotnet run
Hello World!

プログラムに日本語を入れてみます。

Program.cs
Console.WriteLine("こんにちは");
Console.WriteLine("Hello World!");
Console.WriteLine("2022年8月5日");

実行

$ dotnet run
こんにちは
Hello World!
2022年8月5日

実行ファイル(バイナリー)を作成するには、

dotnet publish -c release -r linux-x64 --self-contained

作成した実行ファイル(バイナリー)を実行

$ bin/release/net6.0/linux-x64/example 
こんにちは
Hello World!
2022年8月5日

Mono でコンパイル、実行する方法です。
Mono で C# を使う

13
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
14