Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling a specific compiler warning in VS Code

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.

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

For #1: I can't find the Solution Explorer anywhere within VS Code.

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.

Updates:

I tried using <noWarn>01699,8019</noWarn> in my .csproj files, but no go.

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.

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?

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.

like image 409
Patrick vD Avatar asked Jan 25 '16 21:01

Patrick vD


People also ask

How do I stop compiler warnings?

Choose Build, and go to the Errors and warnings subsection. In the Suppress warnings or Suppress specific warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons. For a list and descriptions of warning codes, see C# Compiler Messages. Rebuild the solution.

How do I turn on compiler warnings in Visual Studio?

If you want to turn it on (or off) in the project setting, you have to go to: Configuration Properties -> C/C++ -> Command Line and then under Additional Options you can enter: /w3#### to set your warning to level 3, and thus enable it; or you can enter /wd#### to disable a warning.

How do I turn off GCC warnings?

To answer your question about disabling specific warnings in GCC, you can enable specific warnings in GCC with -Wxxxx and disable them with -Wno-xxxx. From the GCC Warning Options: You can request many specific warnings with options beginning -W , for example -Wimplicit to request warnings on implicit declarations.


1 Answers

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> is PascalCase rather than camelCase, and the element is nested inside of a <PropertyGroup>.

like image 138
skmichaelson Avatar answered Nov 07 '22 16:11

skmichaelson