如何在VS Code和/或.NET Core中设置编译器选项? [英] How to set compiler options in VS Code and/or .NET Core?

查看:618
本文介绍了如何在VS Code和/或.NET Core中设置编译器选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用VS Code作为IDE,为通过.NET Core编写的C#库项目设置-checked编译器选项。我该怎么办?

I'm trying to set the -checked compiler option for a C# library project written over .NET Core, using VS Code as the IDE. How can I do this?

推荐答案

使用VS Code打开项目/解决方案时,它将创建一个名为<$的目录。 c $ c> .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)

您可以通过在每个任务的<$ c $中添加一个字符串来为每个任务添加单独的参数c> 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

这篇关于如何在VS Code和/或.NET Core中设置编译器选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆