Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StyleCop settings file could not be saved

Tags:

stylecop

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?

like image 502
Troy Hunt Avatar asked Nov 03 '10 23:11

Troy Hunt


People also ask

How do I enable StyleCop in VS 2022?

The stylecop feature doesn't work with Visual Studio 2022 . The Compatible versions are Visual Studio 2012, 2013, 2015, 2017, 2019 . Please try to always add a source to statements like this (even if it is obviously correct in this case 😉).

How do I configure StyleCop?

Configuring StyleCop is done in two optional steps. First, you can use rule set files to configure which rules are checked and how strongly you feel about them. Second, you can add a stylecop. json file to your project to fine-tune some rules.

How do I open StyleCop settings editor?

If you are on Windows, the Settings. StyleCop file can be opened from the Explorer and edited through a GUI. If that doesn't work, try dragging the Settings file onto an application called StyleCopSettingsEditor.exe which is installed in your StyleCop Program Files folder.

How do you change rules on StyleCop?

In your StyleCop install, there's a Settings. StyleCop file. You can edit this to turn off rules globally. Drag that file onto the Settings Editor executable in that file to edit it.


3 Answers

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.

like image 136
Task Avatar answered Oct 10 '22 02:10

Task


  • Right click on project,
  • Select StyleCop Settings,
  • Navigate to 'Setting Files' tab,
  • Select 'Merge with settings file found in parent folders' and click on Edit,
  • You will get Warning message.
  • On clicking on Yes you are able to edit the StyleCop.settings file.

Note: You are about to edit the default settings which are applied to all code on which this installation of StyleCop is run.

like image 43
Dhananjaya Avatar answered Oct 10 '22 04:10

Dhananjaya


This has nothing to do with StyleCop. You are being restricted by Windows security since you're trying to edit something in the Program Files folder. By default StyleCop is set up so that you shouldn't need to edit that file, ever.

like image 33
Jason Allor Avatar answered Oct 10 '22 02:10

Jason Allor