Visual Studio Code, C# support on Windows

16.6k views Asked by At

I want to try out a new editor from Microsoft - Visual Studio Code. I want to implement a simple app (like Hello, World) and be able to debug it. But after a lot of googling and trying, I didn't manage to do that. Is that possible? I have Windows 10 with Visual Studio 2015 installed.

What I've tried to do:

1) Uncomment the following in the tasks.json file:

{
"version": "0.1.0",
"command": "msbuild",
"args": [
    // Ask msbuild to generate full paths for file names.
    "/property:GenerateFullPaths=true"
],
"taskSelector": "/t:",
"showOutput": "silent",
"tasks": [
    {
        "taskName": "build",
        // Show the output window only if unrecognized errors occur.
        "showOutput": "silent",
        // Use the standard MS compiler pattern to detect errors, warnings
        // and infos in the output.
        "problemMatcher": "$msCompile"
    }
]

But compiling (ctrl-shift-b) fails with the error: "Failed to launch external program msbuild . spawn msbuild ENOENT"

2) Read this article: http://michaelcrump.net/creating-and-debugging-console-apps-with-vscode/, but I don't have any project.json file, also "dnx . run" fails with the error "System.InvalidOperationException: Unable to resolve project"

Is there a simple way to run simple C# app in VS Code? I'm wondering why it's so complicated. Probably, I'm missing something, any ideas are welcome.

Update 1: Adding msbuild to path helps

3

There are 3 answers

0
Oleksii Kondratenko On

Had the same problem. Changed direct path to msbuild fixed it:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "windows": {
        "command": "C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe"
    },
   // "command": "msbuild",
    "args": [
        // Ask msbuild to generate full paths for file names.
        "/property:GenerateFullPaths=true"
    ],
    "taskSelector": "/t:",
    "showOutput": "silent",
    "tasks": [
        {
            "taskName": "build",
            // Show the output window only if unrecognized errors occur.
            "showOutput": "silent",
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}
0
James Vickery On

The C# support in VS Code is optimized for cross platform .NET development (DNX) (see working with ASP.NET 5 and VS Code for another relevant article. Our focus with VS Code is to be a great editor for cross platfrom C# development - for instance many Unity developers have been enjoying using VS Code in place of Mono Develop.

We support debugging of C# apps cross platfrom via Mono (see Mono Debugging).

Due to this focus many standard C# project types are not recognised by VS Code. An example of a non-supported project type is an ASP .NET MVC Application. In these cases if you simply want to have a lightweight tool to edit a file - VS Code has you covered. If you want the best possible experience for those projects, and development on Windows in general we recomend you use Visual Studio Community.

from: code.visualstudio.com/Docs/languages/csharp


Update, June 2017:

C# is supported in Visual Studio Code using Microsoft's VS Code C# extension: https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp

This can be installed by searching for 'C#' in Extensions: Install Extension. Alternatively, opening a .cs file should prompt to install extension.

This extension supports debugging of C# applications running on .NET Core or Mono, however does not support debugging applications running on the Desktop .NET Framework - Visual Studio Community is still recommended for full .NET project support.

For more info regarding VS Code's C# support, see https://code.visualstudio.com/docs/languages/csharp

For the marketplace page for the VS Code C# extension, see https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp

0
illegal-immigrant On

You can set up msbuild for building full .NET apps just fine, note you either have to have msbuild on path or provide full path to it in command property. This is what example build task (bound to ctrl + shift + b) looks like:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "MSBuild.exe",
    "args": [
        // $msCompile requires GenerateFullPaths=true, rest is optional. I set it to build Debug/Any CPU and use parallel project build
        "${workspaceRoot}/src/ExampleSolution.sln",
        "/p:Configuration=Debug;Platform=Any CPU;GenerateFullPaths=true",
        "/m"
    ],
    "taskSelector": "/t:",
    "showOutput": "silent",
    "echoCommand": true,
    "tasks": [
        {
            "taskName": "Rebuild",
            // Required if you want "Rebuild", not build as your target and still use ctrl + shift + b hotkey
            "isBuildCommand": true,
            // Show the output window only if unrecognized errors occur.
            "showOutput": "silent",
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}

UPD: If you want to set up both building and unit test running, you can use something like this (uses nunit console runner and cmd as a task to hack around vscode limitation of supporting only single task):

{
    "version": "0.1.0",
    "command": "cmd",
    "args": [
        "/c"
    ],
    "showOutput": "always",
    "echoCommand": true,
    "tasks": [
        {
            "isBuildCommand": true,
            "taskName": "MSBuild.exe",
            "args": [
                "${workspaceRoot}/src/Example.sln",
                "/t:Rebuild",
                "/p:Configuration=Debug;Platform=Any CPU;GenerateFullPaths=true",
                "/m"
            ],
            "showOutput": "always",
            "problemMatcher": "$msCompile"
        },
        {
            "taskName": "nunit3-console.exe",
            "args": [
                "${workspaceRoot}/src/Example.sln"
            ],
            "showOutput": "always"
        }
    ]
}