在 Ubuntu 上使用 VSCode 编译 C# 项目

Compiling C# projects with VSCode on Ubuntu

我根据 documentation 中可用的各种教程在 Ubuntu 14.04 上设置了 VSCode - 我尝试了尽可能多的内容。编辑器运行没有问题,并且(在解决了 Mono 版本差异之后)提供了比我认为的大多数替代品更好的编码体验。

我在尝试编译 C# 项目时遇到了问题。这是我在完成入门指南时所期望的功能。在按下 ctrl + shift + B 后,系统最初提示我创建一个 tasks.json文件,该文件旨在提供项目特定的快捷键操作配置。从最初 tasks.json 生成的评论来看,它似乎以 Windows 为目标,并且指的是一个 tsc.exe 程序,它是一个 TypeScript 编译器。

我曾在同一台笔记本电脑上使用 MonoDevelop 构建项目,但从未设置过编译步骤。我假设这应该是开箱即用的功能是错误的,还是我错过了正确处理 C# 项目的步骤?

昨晚翻默认tasks.json文件的时候一定是急躁了。有一个部分提到了 msbuild(朝向底部):

// Uncomment the section below to use msbuild and generate problems 
// for csc, cpp, tsc and vb. The configuration assumes that msbuild 
// is available on the path and a solution file exists in the  
// workspace folder root. 
/* 
{   
    "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"
        }   
     ] 
 }
*/

只需注释掉文件的其余部分,取消注释上面的 JSON 文本,并将 "command" 从 "msbuild" 更改为 "xbuild"(等效于 Mono)。现在点击 ctrl+shift+B 成功编译项目。

希望一旦预览版出来,这种手动修改配置文件的必要性或乏味性就会降低。

编辑

暂时将此标记为答案。如果在产品发展过程中发生变化,将更新或接受更好的答案。