写在前面

鉴于网上教程为数较少,为此写下教程.

此教程适合于广大Mac以及Linux用户,Windows用户可选宇宙无敌的VS.

image-20190124165241642

必要的组件

Mono-mdk
vsc
Mono-debug
安装Mono-sdk
  • Mac :

    brew cask install mono-mdklinux
    
  • linux(Ubuntu)

    sudo apt-get install mono-complete
    

以下命令能正确运行即安装成功

image-20190124165922272

配置vscode

  1. 安装mono-debug , C# 扩展

    image-20190124170038288

  2. 新建一个C#文件夹, 成为你的工作区

    按下 command(ctrl)+shift+P 输入task 回车

    建立tasks.json文件

    复制以下内容到tasks.json

    
    {
    
        "version": "2.0.0",
        // 该命令需要在系统变量内定义
        "tasks": [
            {
                "label": "build",
                "command": "mcs",
                "type": "shell",
                "args": [
                    "${file}","--output","Debug/${fileBasenameNoExtension}.exe"
                ],
                "presentation": {
                    "echo": true,
                    "reveal": "always",
                    "focus": false,
                    "panel": "shared"
                },
                "problemMatcher": []
            }
        ],
    }
    
    

    然后再按下 command(ctrl)+shift+P 输入build 回车

    建立launch.json.

    {
    
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "mono",
                "request": "launch",
                "preLaunchTask": "build",
                "program": "${workspaceRoot}/Debug/${fileBasenameNoExtension}.exe",
                "cwd": "${workspaceRoot}",
                "console": "externalTerminal",
            },
    
        ]
    }
    

    在工作区目录下新建一个Debug文件夹.

    以后调试生成的程序都在这里.

  3. 建立Hello.cs文件, 按下F5进行调试 , 测试通过

    namespace HelloWorld
    {
        class Hello {         
            static void Main(string[] args)
            {
                System.Console.WriteLine("Hello World!!");
            }
        }
    }
    

    image-20190124220714408