How to treat Warning as Error in Visual Studio during build – Part 2

In previous article you learnt about how to treat warning messages as errors in Visual Studio. In this article I will explain how to treat selective warnings as error.

Warning messages do not harm build activity they have been ignored most of the time. As per the good debugging practice, you must consider warning messages as errors and must be cleared by fixing them safely. To make this happen, we must have some mandatory mechanism to consider warning messages as errors.

In the previous article, I have explained how to convert all warning messages as error. But some times not all the warning errors have negative impact on the application. In this case we can choose selective warning messages (level3) and inform compiler to treat them as error.

Recommended:   .NET Core Development Environment Setup

To do this we must have the list of warning messages and its corresponding error codes. The Microsoft repository provides a list of Warning messages and solution. Yow would need to refer these list and prepare the list of warning code to considered as error.

In the below image, I have selected CS0108 and CS0164 warnings.

Once the list is prepared, perform the below steps.

  • Right click on the project you want to enable this on and select the ‘Properties’ in context menu.
  • Select the “Build” tab.
  • Change “Treat warnings as errors” to “Specific Warning” and enter the numeric warning code into the input box. If there are multiple warning code to be treated as error, then enter the multiple numeric code with comma (,) separated
Recommended:   List of C# Compiler Errors and Warnings

Share this:

We will be happy to hear your thoughts

Leave a reply