How to compile c# in Microsoft's new Visual Studio Code?
Since no one else said it, the short-cut to compile (build) a C# app in Visual Studio Code (VSCode) is SHIFT+CTRL+B
.
If you want to see the build errors (because they don't pop-up by default), the shortcut is SHIFT+CTRL+M
.
(I know this question was asking for more than just the build shortcut. But I wanted to answer the question in the title, which wasn't directly answered by other answers/comments.)
Intellisense does work for C# 6, and it's great.
For running console apps you should set up some additional tools:
- ASP.NET 5; in Powershell:
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
- Node.js including package manager
npm
. - The rest of required tools including Yeoman
yo
:npm install -g yo grunt-cli generator-aspnet bower
- You should also invoke .NET Version Manager:
c:\Users\Username\.dnx\bin\dnvm.cmd upgrade -u
Then you can use yo
as wizard for Console Application: yo aspnet
Choose name and project type. After that go to created folder cd ./MyNewConsoleApp/
and run dnu restore
To execute your program just type >run
in Command Palette (Ctrl+Shift+P
), or execute dnx . run
in shell from the directory of your project.
Install the extension "Code Runner". Check if you can compile your program with csc
(ex.: csc hello.cs
). The command csc
is shipped with Mono. Then add this to your VS Code user settings:
"code-runner.executorMap": {
"csharp": "echo '# calling mono\n' && cd $dir && csc /nologo $fileName && mono $dir$fileNameWithoutExt.exe",
// "csharp": "echo '# calling dotnet run\n' && dotnet run"
}
Open your C# file and use the execution key of Code Runner.
Edit: also added dotnet run
, so you can choose how you want to execute your program: with Mono, or with dotnet. If you choose dotnet, then first create the project (dotnet new console
, dotnet restore
).