首先配置好.NET Framework环境变量 :
(本例中将C:\Windows\Microsoft.NET\Framework64\v4.0.30319
加入Path
中即可)。重启 Powershell ,确保输入csc
能找到编译器。

在VS code中安装好 Code Runner 扩展,进入设置,直接点击在settings.json中编辑
。

在 settings.json 中加入:
"code-runner.executorMap": {
"csharp": "echo= && csc /nologo /utf8output $fileName && $fileNameWithoutExt"
}

打开一个.cs文件,直接点击三角形按钮运行,最终输出效果基本和nodejs等脚本语言无异:

补充解释一下各参数的作用:
echo=
换行,保持美观/nologo
取消编译器版权信息/utf8output
以 UTF-8 编码格式输出编译器消息,防止编译出错时显示的中文乱码(如图)

SEO相关:.net中文乱码,csc,VS code csharp,Code Runner,在VS code中编写运行C#
另外需要输入的程序可以如下配置:
{
"code-runner.saveAllFilesBeforeRun": true,
"code-runner.saveFileBeforeRun": true,
"code-runner.executorMap": {
"csharp": "clear && echo '' && csc /nologo /utf8output $fileName && .\\$fileNameWithoutExt"
},
"code-runner.fileDirectoryAsCwd": true,
"code-runner.preserveFocus": false,
"code-runner.runInTerminal": true
}