【问题标题】:Visual Studio Code: How to configure 'dotnet' not to show warnings when compilingVisual Studio Code:如何配置“dotnet”在编译时不显示警告
【发布时间】:2018-06-20 21:42:42
【问题描述】:

好的。我在 .NET Core 中并在 Mac 机器上使用 Visual Studio Code。现在,每当我运行我的 C# 项目时,Visual Studio Code 都会显示这条烦人的消息:

preLaunch 任务“构建”以退出代码 1 终止

它向我显示了单击一个名为“显示问题”的按钮的选项。当我点击这个按钮时,它只显示警告信息。

现在,如果是错误,则可以看到此消息。但事实上,每次有警告时它都会显示这条消息(这对我来说是可以的)。这很烦人。有没有办法可以将 Visual Studio Code 配置为不在警告之类的内容上显示这些消息?

【问题讨论】:

标签: c# asp.net-core visual-studio-code


【解决方案1】:

您的task.json 文件可能有问题。检查文件的参数并确保构建指向正确的位置:

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

【讨论】:

    【解决方案2】:

    为了禁用警告,您应该在tasks.json 文件中将-nowarn 添加到args

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "command": "dotnet",
                "type": "process",
                "args": [
                    "build",
                    "${workspaceFolder}/MyProject.csproj",
                    "-nowarn" // here
                ],
                "problemMatcher": "$msCompile"
            }
        ]
    }
    

    【讨论】:

    • 但正如我在上面的问题中提到的,我只能在终端中看到警告。我的意思是,如果无论如何要配置 VS Code,它不会因为诸如警告之类的琐碎原因而显示此消息?
    • @WorkBee 所以你的主题应该是:如何配置dotnet在编译时不显示警告,因为vscode只是运行task.json中的代码。
    猜你喜欢
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    • 2020-03-12
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    相关资源
    最近更新 更多