How can I suppress Intellisense errors for certain files?

北慕城南 提交于 2020-01-04 04:00:49

问题


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#

  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, 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!