Search code examples
winformsvisual-studiotelerikwarningsvisual-studio-2008-sp1

Hide a specific instance of a warning in Visual Studio?


I am working on a Windows Forms project that uses Telerik RadControls, including the RadGridView. The control in question automatically creates a RadGridView instance named MasterTemplate as a class member, as well as the one I named, due to the way it works internally.

This causes Visual Studio to give me a "The field [...] is never used" warning for each RadGridView in the entire project, of which there are many.

  • Editing the .designer.cs file is pointless as it would be edited by the designer itself.
  • While it may be possible to suppress all warnings of this type, I don't want to do so because it would also hide warnings about fields that I created.
  • Leaving the warnings there is unnecessarily cluttering the Error List window, so I have to hide all warnings if I want to see only the errors. I then re-enable the display of the warnings and have to read the list carefully to see if there are any "legitimate" warnings in it.

Is it in any way possible to tell Visual Studio to "never bother me with this warning about this variable again, but do keep telling me about other warnings"?


Solution

  • From Microsoft's documentation for Visual Studio, How to: Suppress compiler warnings:

    Suppress specific warnings for Visual C# or F# 

    Use the Build property page to suppress specific warnings for C# and F# projects.

    1. In Solution Explorer, choose the project in which you want to suppress warnings.

    2. On the menu bar, choose View > Property Pages.

    3. Choose the Build page.

    4. In the Suppress warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons.

    5. Rebuild the solution.

    According to this documentation, the ability to suppress the display of specified warnings was made available at least as far back as Visual Studio 2015. I can confirm that this guidance is working for me in Visual Studio 2017. Also, I have found that whitespace is permitted after the semicolon (and before as well, if you like). For example:

    CS1587; CS1591
    

    Finally, the linked documentation indicates that warnings can also be suppressed for the following:

    • Visual C++
    • Visual Basic
    • NuGet packages