Search code examples
stylecop

StyleCop settings file could not be saved


I'm having a problem with StyleCop that's driving me nuts. I recently installed it on a new machine and every time I go to edit the master settings file (either via Visual Studio or the StyleCop editor), I'm getting the following error:

The settings file could not be saved: Access to the path 'C:\Program Files (x86)\Microsoft StyleCop 4.4.1.1\Settings.StyleCop' is denied.

If I run VS as an administrator I can edit the file but then StyleCop for ReSharper doesn't seem to recognise the rule changes. I've uninstalled and reinstalled various versions with the same end result.

Any ideas out there?


Solution

  • Modifying the Settings.StyleCop file in the StyleCop installation directory is possible, but almost always a bad idea.

    The best way to go about this kind of thing is to modify the Settings.StyleCop file in the project directory. I believe one is created when you right-click on a project and open the settings that way.

    What often happens though is that you find you need exactly the same settings in ALL your projects, and the settings are wrong until you go through this manual process of configuring the project. The way around that is this:

    Once you have a single project configured the right way, move the Settings.StyleCop file up one directory. Now you have settings for the solution instead of just the project. All projects in the solution will now have the same settings! This means that now you can create a project-level Settings.StyleCop file for any project that doesn't need the 'typical' settings. You can even take it a level further and move the Settings.StyleCop file up to the "source control root" (often at least one level higher than the solution level) and now all your solutions will have the same settings.