最短コマンド
dotnet new console -o MyApp
# cd MyApp
# dotnet add package Newtonsoft.Json
# nvim MyApp/Program.cs
dotnet run
説明
- コマンドプロンプト,Powershellまたはターミナルを開き、次のコマンドを実行します:
dotnet new console -o MyApp
cd MyApp
- 次に、ライブラリを追加します。(任意)
dotnet add package Newtonsoft.Json
-
Program.cs
ファイルを編集します:(任意)
nvim MyApp/Program.cs
using System;
using System.IO;
using Newtonsoft.Json;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
string filePath = "test.txt";
// ファイルを開く
using (StreamReader file = File.OpenText(filePath))
{
string content = file.ReadToEnd(); // ファイルの内容を読み取る
Console.WriteLine(content); // ファイルの内容をコンソールに出力する
} // ファイルを閉じる
}
}
}
- 最後に、アプリケーションをビルドして実行します:
dotnet run