Setup

  1. Install the latest mono as described at http://www.mono-project.com/docs/getting-started/install/linux/#debian-ubuntu-and-derivatives.
  2. Install Visual Studio Code from https://code.visualstudio.com Just unpack and start.

Simple Scenario (no debug and no IntelliSense)

Code

./program.cs

1public static class Programm
2{
3 public static void Main()
4 {
5 Console.WriteLine("Hello Mono and VS Code!!!");
6 }
7}

Project configuration

For simple applications without debugging support you can skip the creation of project.json or any other file like this.

Build configuration

./.vscode/tasks.json

In following task configuration we use msc (mono C# compiler) as a build tool with our single code file as an argument and msCompile problem matcher.

1{
2 "version": "0.1.0",
3 "command": "mcs",
4 "isShellCommand": true,
5 "showOutput": "silent",
6 "args": ["program.cs"],
7 "problemMatcher": "$msCompile"
8}

Launch configuration

Just press F5 and VS Code will auto-generate launch.json that we need.

1{
2 "version": "0.2.0",
3 "configurations": [
4 {
5 "name": "Launch",
6 "type": "mono",
7 "request": "launch",
8 "program": "${workspaceRoot}/program.exe",
9 "args": [],
10 "cwd": "${workspaceRoot}",
11 "runtimeExecutable": null,
12 "env": {},
13 "externalConsole": false
14 },
15 {
16 "name": "Attach",
17 "type": "mono",
18 "request": "attach",
19 "address": "localhost",
20 "port": 5858
21 }
22 ]
23}

And that’s it

  • Ctrl+Shift+B to build
  • F5 to run and see the output in debug console

Complete scenario

If you need to add a debugger and IntelliSense support to the simple project described above just add project.json

Additional setup

To use project.json we need to install DNX as fas as project.json is part of dnx build system. Run the following commands to install DNX for mono:

1curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
2dnvm upgrade -r mono

./project.json

Below is a simple project.json file that includes all *.cs file in all subdirectories and use dnx451 as a framework. Taking into account that we have configured DNX to use mono dnx451 means mono in our case.

1{
2 "configurations": {
3 "Debug": {
4 "compilationOptions": {
5 "define": ["DEBUG", "TRACE"]
6 }
7 },
8 "Release": {
9 "compilationOptions": {
10 "define": ["RELEASE", "TRACE"],
11 "optimize": true
12 }
13 }
14 },
15 "frameworks": {
16 "dnx451": {
17 "frameworkAssemblies": {
18 "System": ""
19 }
20 }
21 },
22 "dependencies": { },
23 "compile": "*/**/*.cs"
24}

After that, you can navigate in code using IntelliSense, but you are still not able to debug your program because mcs does not produce *.mdb by default. To fix this problem just debug to mcs arguments in tasks.json

./taks.json

1{
2 "version": "0.1.0",
3 "command": "mcs",
4 "isShellCommand": true,
5 "showOutput": "silent",
6 "args": ["program.cs","--debug"],
7 "problemMatcher": "$msCompile"
8}

Now you can work with all functionalities of VS Code. Just press F5 and start debugging!

Complex projects

For complex projects just use your favorite build tool in tasks.json (see [prev post] for more details about tasks.json)

Some useful links

Mono Project

Visual Studio Code

Schema for tasks.json

task.json description

Debugging in Visual Studio Code

Version Control in Visual Studio Code