How to create a Visual Studio build configuration with StyleCop code analysis disabled?

≡放荡痞女 提交于 2019-12-22 09:57:23

问题


Question

I have installed StyleCop and now there are StyleCop squiggly lines all over the source code.

Now, I'd like to be able to temporarily enable and disable StyleCop's analysis.

I would have expected a checkbox saying "Disable StyleCop", instead, the Internet tells me that I have to create a new Visual Studio build configuration called "Debug without StyleCop" open the project *.csproj file and do all kinds of nasty things in there.

Can anyone please provide a step by step instruction on how to do that?

What I have found so far

I've tried to do my homework first and found this Stackoverflow question Visual Studio: temporarily disable StyleCop. But the answer didn't provide enough information for me to solve the problem -- or I just made a mistake while trying it out since I've never touched a *.csproj file and don't know what I was doing there.

What I have tried

  1. Create a new Visual Studio build configuration
  2. In the Solution Explorer, select my project MyProject.csproj and click "Unload project"
  3. In the Solution Explorer, select my project MyProject.csproj and click "Edit MyProject.csproj"
  4. Make the changes as suggested in the above mentioned answer.
  5. In the Solution Explorer, select my project MyProject.csproj and click "Reload Project"
  6. Select build configuration "Debug without StyleCop"
  7. Rebuild with F6
  8. The StyleCop squiggly lines are still there
  9. Restart Visual Studio
  10. The StyleCop squiggly lines are still there

Where did I go wrong?

Versions

  • Visual Studio 2012 Professional
  • StyleCop 4.7.47.0 (with ReSharper integration)
  • ReSharper 7.1

回答1:


The StyleCop Plugin for Resharper is creating your squigglies, not the StyleCop task for MsBuild. As far as I know the StyleCop plugin doesn't check your project file settings, but is fully triggered by the presence of a Setting.StyleCop file plus the Resharper settings that are made the same between StyleCop and Resharper's code formatting section.

Because if that, trying to remove StyleCop completely through the MsBuild .*proj files won't turn off the squigglies. You will need to turn off the plugin in the Resharper Settings.

To verify this, you can look at the MsBuild output when you run a build. your StyleCop warnings shouldn't be showing up in the MsBuild Output window, but they will still show up in the Error window and in the editor due to the fact that Resharper runs StylecCop continuously in the background.

As far as I can tell, there is no easy way to turn off StyleCop completely through the project files when you have Resharper enabled.

What you can do is: rename the Settings.Stylecop file or overwrite it with one that turns off StyleCop altogether, this will leave the Resharper code formatting rules enabled, but will turn off specific StyleCop rules



来源:https://stackoverflow.com/questions/20302700/how-to-create-a-visual-studio-build-configuration-with-stylecop-code-analysis-di

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