This post adds a sample as addition to my post about VS Code previous post
Setup
- Install latest mono as described at http://www.mono-project.com/docs/getting-started/install/linux/#debian-ubuntu-and-derivatives.
- Install Visual Studio Code from https://code.visualstudio.com Just unpack and start.
Simple Scenario (no debug and no IntelliSense)
Code
./program.cs
[code lang=csharp]
public static class Programm
{
public static void Main()
{
Console.WriteLine("Hello Mono and VS Code!!!");
}
}
[/code]
Project configuration
For simple applications without debug support you can skip 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 build tool with our single code file as an argument and msCompile problem matcher.
[code lang=javascript]
{
"version": "0.1.0",
"command": "mcs",
"isShellCommand": true,
"showOutput": "silent",
"args": ["program.cs"],
"problemMatcher": "$msCompile"
}
[/code]
Launch configuration
Just press F5 and VS Code will auto-generate launch.json that we need.
[code lang=javascript]
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "mono",
"request": "launch",
"program": "${workspaceRoot}/program.exe",
"args": [],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"env": {},
"externalConsole": false
},
{
"name": "Attach",
"type": "mono",
"request": "attach",
"address": "localhost",
"port": 5858
}
]
}
[/code]
And that’s it
- Ctrl+Shift+B to build
- F5 to run and see output in debug console
Complete scenario
If you need to add debugger and IntelliSense support to 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 following commands to install DNX for mono:
[code lang=bash]
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
dnvm upgrade -r mono
[/code]
./project.json
Below is a simple project.json file that includes all *.cs file in all subdirectories and use dnx451 as framework. Taking into account that we have configured DNX to use mono dnx451 means mono in our case.
[code lang=javascript]
{
"configurations": {
"Debug": {
"compilationOptions": {
"define": ["DEBUG", "TRACE"]
}
},
"Release": {
"compilationOptions": {
"define": ["RELEASE", "TRACE"],
"optimize": true
}
}
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System": ""
}
}
},
"dependencies": {
},
"compile": "*/**/*.cs"
}
[/code]
After that you can navigate in code use IntelliSense but you 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
[code lang=javascript]
{
"version": "0.1.0",
"command": "mcs",
"isShellCommand": true,
"showOutput": "silent",
"args": ["program.cs","–debug"],
"problemMatcher": "$msCompile"
}
[/code]
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)