realPro
realPro

Reputation: 1846

Omitting the "The variable X is declared but never used" from VS build output

Is it possible to omit only the missing variable warnings like: The variable 'ex' is declared but never used? I don't care about these variables.

Upvotes: 1

Views: 1178

Answers (1)

Adrian Mole
Adrian Mole

Reputation: 51835

Assuming this warning is occurring when you are building a C# project (there are very similar ones for other languages), then you can disable it in your project's "Properties".

Right-click the project in the Solution Explorer, and select "Properties" (at or near the bottom of the pop-up menu). Then, in the properties display, select the "Build" tab from the list on the left, and add 168 (you may need to enter the full warning code, CS0168) in the "Suppress Warnings" edit box:

enter image description here

Of course, a better way to avoid the warning is not to declare variables that you don't use! However, I understand that this is sometimes useful during developmental and debug stages: and note, this setting is configuration-specific, so you could suppress the warning in your "Debug" build but allow it in your (final) "Release" build.

If you are using another language (like C++ or C), you can suppress the warning in a very similar manner. I can modify this answer, if that it the case.

Upvotes: 1

Related Questions