且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在VS Code和/或.NET Core中设置编译器选项?

更新时间:2022-12-22 15:34:34

使用VS Code打开项目/解决方案时,它将创建一个名为 .vscode ,其中会有一个 tasks.json 文件

When you open your project/solution with VS Code, it will create a directory called .vscode, within it there will be a tasks.json file

(此目录和文件是第一次在VS Code中按F5创建的)

(this directory and file are created the first time that you hit F5 within VS Code)

看看该文件,您会发现它采用了一种格式类似于以下内容:

Taking a look at this file, you'll that it takes a format similar to the following:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/project.csproj"
            ],
            "problemMatcher": "$tsc"
        }
    ]
}

(您可能会有更多任务条目)

(you may have more task entries)

您可以通过在每个任务的 args 数组。在上面的示例中,我调用CLI命令 dotnet ,并向其传递参数 build $ {workspaceFolder} /project.csproj

You can add individual arguments to each task by adding a string to its args array. In the above example I am calling the CLI command dotnet and passing it the arguments build and ${workspaceFolder}/project.csproj