在VS Code中禁用特定的编译器警告 [英] Disabling a specific compiler warning in VS Code
问题描述
我想知道如何在整个项目的VS Code 中取消特定的编译器警告.
我已经看到以下问题:是否可以禁用特定的编译器警告?,但适用于Visual Studio,而不适用于Visual Studio代码.
I want to know how to suppress a specific compiler warning within VS Code for the entire project.
I have seen this queston: Is it possible to disable specific compiler warnings? but it is for Visual studio, not Visual Studio Code.
以下是上面链接的问题中推荐的答案:
1. 解决方案资源管理器
> 查看
> 属性
> Build
> 禁止警告
和
2. #pragma警告禁用警告列表
Here are the answers that where recommended in the question linked above:
1. Solution Explorer
> View
> Properties
> Build
> Suppress Warnings
and
2. #pragma warning disable warning-list
对于#1:我在VS Code中的任何地方都找不到解决方案资源管理器.
For #1: I can't find the Solution Explorer anywhere within VS Code.
对于#2仅当我将其包含在每个脚本的顶部时,此方法才有效.我需要为整个项目做到这一点.
For #2 This only works if I include it at the top of each of the scripts. I need a way to do so for the entire Project.
更新:
我尝试在.csproj文件中使用< noWarn> 01699,8019</noWarn
>,但没有成功.
I tried using <noWarn>01699,8019</noWarn
> in my .csproj files, but no go.
查看最后的更改后,我注意到它已恢复为< noWarn> 0169</noWarn>
.然后,我意识到我需要的是< noWarn> 0169; 8019</noWarn>
.切换,
为;
即可解决问题.
After reviewing the last changes, I noticed that it had reverted to <noWarn>0169</noWarn>
. I then realised that what I needed was <noWarn>0169;8019</noWarn>
. Switching the ,
for a ;
Solved the problem.
好吧,事实证明上述解决方案根本没有用.重新启动VS Code后,所有警告均会再次出现.也许我需要的错误代码不是8019,即使它可以用作 #pragma
语句中的错误代码.< noWarn> 中使用的代码是否不同于 #pragma
语句末尾使用的代码?
Well, it turns out that the above solution didn't work after all. As soon as I restarted VS Code, all the warnings came back. Maybe the error code I need isn't 8019, even though it worked as the error code within a #pragma
statement. Are the codes used within a <noWarn>
different than the codes used at the end of a #pragma
statement?
对于那些也转向VS社区的人来说,这不是重点.我正在使用与 Unity编辑器一起使用VS Code AS文本编辑器.我正在寻找我需要更改的文件以及需要进行哪些更改,以将 #pragma warning disable 8019
之类的语句应用于 entire 项目.
For those saying too switch to VS Community, that's not the point. I'm using VS Code AS a text editor with Unity Editor. I'm looking for which file I need to change and what changes need to be made to apply a statement like #pragma warning disable 8019
to the entire project.
推荐答案
我能够使它正常工作.我的解决方案如下所示:
I was able to get this to work. My solution looks something like this:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
<NoWarn>0169;8019</NoWarn>
</PropertyGroup>
< NoWarn>
是PascalCase而不是camelCase,并且该元素嵌套在< PropertyGroup>
内.
<NoWarn>
is PascalCase rather than camelCase, and the element is nested inside of a <PropertyGroup>
.
这篇关于在VS Code中禁用特定的编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!