问题
Visual Studio 2015 offers the option to show Intellisense errors in the same window that also displays regular build errors. I like it because I don't even need to build in order to see if my code is sytatictically correct.
However, the window also shows one false positive error which seems to be related to an Intellisense bug. Is there any way to suppress intellisense errors for specific code regions or entire files?
回答1:
Did you find an answer? You can do it by writing the following in your code on the line prior to where the error is raised
#pragma warning disable XXXX
where XXXX is the error code without the "CS"
Or you can try these steps to suppress specific warnings for Visual C# or F#
- In Solution Explorer, choose the project in which you want to suppress warnings.
- On the menu bar, choose View, Property Pages.
- Choose the Build page.
- In the Suppress warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons, and then rebuild the solution.
taken from here https://msdn.microsoft.com/en-us/library/jj715718.aspx
Note that warnings are mentioned rather than errors, but for me they are listed as errors if I choose to show Suppressed Errors in the Error List window. You might need to enable this column in the Error List window.
回答2:
When using StyleCop you can do the following:
[SuppressMessage("Rule Category", "Rule Id", "Justification")]
Example:
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules",
"SA1300:ElementMustBeginWithUpperCaseLetter",
Justification = "This field is intentionally lowercase")]
来源:https://stackoverflow.com/questions/32697129/how-can-i-suppress-intellisense-errors-for-certain-files