问题
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
- Create a new Visual Studio build configuration
- In the Solution Explorer, select my project MyProject.csproj and click "Unload project"
- In the Solution Explorer, select my project MyProject.csproj and click "Edit MyProject.csproj"
- Make the changes as suggested in the above mentioned answer.
- In the Solution Explorer, select my project MyProject.csproj and click "Reload Project"
- Select build configuration "Debug without StyleCop"
- Rebuild with F6
- The StyleCop squiggly lines are still there
- Restart Visual Studio
- 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