Retrieving the warning ID:
The warning ID can be taken from the Build Output. In the following example, the warning ID is 0169 (we only need the numeric part).
test.cs(17,9): warning CS0169: The private field ‘foo.c’ is never used
VB.NET projects: By modifying project file (.vbproj)
To suppress this warning in VB .NET we need to manually edit project .vbproj file.
- Close VS.
- Open .vbproj file. Find tag and add the warning ID there separated by commas. Don’t place any whitespaces and newlines in this tag! There is one
section for each configuration (Release/Debug) so you need to edit all of them.
- Save the .vbproj file and open VS.
After this, you shouldn’t’t get specified warnings during the build nor should you see warning underline during editing.
A variable, property, or function return is declared with a data type that is not CLS-compliant.
For an application to be compliant with theCommon Language Specification (CLS), it must use only CLS-compliant types.
To disable these warnings, use the following warning numbers:
Reference: How to disable ‘not CLS-compliant’ warnings?, http://www.vbforums.com/archive/index.php/t-481759.html
(2) XML-comment related warnings
XML comment block cannot be associated with any language element that supports the application of XML documentation comments. XML comment will be ignored.
XML comment has a tag with a ‘cref’ attribute ‘^abc.txt’ that could not be resolved. XML comment will be ignored.
VB.NET projects: using Visual Studio Team Suite:
In the Project Properties > Code Analysis section, expand your warning messages and uncheck the one you don’t want to show up.
C# projects: change build properties
To disable warnings, add the warning numbers separated by comma to the Suppress Warnings text box under Project Properties/Build:
Suppress warnings from code
A pretty cool feature in .NET 2.0 is the ability knowingly disable a list of warnings using the #pragma directive.
public class foo
// Disable warnings for unused or unassigned fields
#pragma warning disable 0169, 0414
// No warning
// No warning
int b = 0;
// Restore warnings for unused or unassigned fields
#pragma warning restore 0169, 0414
// Warning CS0169 issued
// Warning CS0414 issued
int d = 0;
// Disable warning messages 4507 and 4034.
#pragma warning( disable : 4507 34 )
// Issue warning 4385 only once.
#pragma warning( once : 4385 )
// Report warning 4164 as an error.
#pragma warning( error : 164 )
// Or all the above 3 in one line:
#pragma warning( disable : 4507 34; once : 4385; error : 164 )