vscode 运行CSharp
2022年6月6日
vscode 运行CSharp
Vscode 运行 CShape
定义
首先配置好. 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
}
参考
Loading...