在 Ubuntu 20.04 中尝试在 VS Code 中运行 C# 代码时出现 scriptcs 错误

5 .net c# visual-studio-code

[运行] scriptcs "/home/yash/netcore/netcore/Program.cs" /bin/sh: 1: scriptcs: not found

[完成] 在 0.012 秒内以代码 = 127 退出

Yas*_*oda 3

如果您想运行 Mono 或 Microsoft .NET 软件,而您不是从 Debian 软件包安装,则需要安装 mono-complete。

然后,安装 mono-complete。在所有当前支持的 Ubuntu 版本中打开终端并输入:

sudo apt install mono-complete
Run Code Online (Sandbox Code Playgroud)

将 C# 代码保存在名为 hello.cs 的文件中。hello.cs 代码示例为: 使 hello.cs 可执行。右键单击 hello.cs 文件 -> 选择属性 -> 权限选项卡 -> 在允许将文件作为程序执行左侧打勾。

使用该cd命令将目录更改为包含 hello.cs 文件的目录。

使用mcs编译器并从源 hello.cs 创建一个名为 hello.exe 的 Windows 可执行文件:

mcs -out:hello.exe hello.cs
Run Code Online (Sandbox Code Playgroud)

使用 mono 运行 hello.exe 程序:

mono hello.exe
Run Code Online (Sandbox Code Playgroud)

在步骤 6. 中运行程序的结果应该是:

你好世界!

按 Enter 键退出回到默认终端提示符。

反编译可执行文件。

monodis --output=decompiled-hello.txt hello.exe
Run Code Online (Sandbox Code Playgroud)