2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[C#] VSCode で dotnet run file.cs

2
Last updated at Posted at 2026-04-18

.NET10で追加された dotnet run file.cs ファイル ベースのアプリ 機能は便利ですが、やはりコード補完やデバッガが使いたいです。

VSCodeでファイルベースのアプリを簡単に扱う方法をメモします。

一言でいうと

フォルダに以下の launch.json を入れておくだけです。

launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET: Launch Active File",
      "type": "coreclr",
      "request": "launch",
      "program": "dotnet",
      "args": ["run", "${file}"],
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
      "console": "internalConsole"
    }
  ]
}

手順

フォルダを1つ作ります。今回は「test」にしました。
このフォルダに上記のlaunch.jsonファイルを置きます。
image.png

これで準備完了です。
(もちろんdotnet環境、C#のVS拡張は別途準備ください)

このフォルダをVSCodeで開きましょう。
image.png

ここにC#のプログラムを1ファイル毎に作ります。
例として、3つのプログラムを1フォルダに入れてみました。
image.png

書いたら実行したいファイルで「F5」キーで実行。

  • 日本語ファイル名もOK
  • サブフォルダ内に置いてもOK
  • 現在はブレークポイントも機能します

終わりに

C# の新機能やnugetのライブラリテストをするためにProgram.csしかないプロジェクトを山ほど作っている人も多いと思いますが、これで見通しが良くなりますね。

参考:
https://www.reddit.com/r/dotnet/comments/1l43vzg/vs_code_net_run_any_cs_file_instantly/?tl=ja
https://gist.github.com/elbruno/aca83ccd780dc7decc4dd330ab35aa07

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?