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 开发者_如何学JAVAevery 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?
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.
- 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.
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.
All the other answers appear to be telling you "don't do this", but if you DO wish this feature to work, as Jason answered, it's a security feature in windows stopping you.
To Fix : Run Visual Studio "as administrator" to make that error go away and allow visual studio to save a file in the program files directory.
精彩评论