StyleCop 设置文件无法保存
我遇到了 StyleCop 的问题,这让我抓狂。我最近将其安装在一台新机器上,每次编辑主设置文件(通过 Visual Studio 或 StyleCop 编辑器)时,都会收到以下错误:
无法保存设置文件: 访问路径“C:\Program Files” (x86)\微软 StyleCop 4.4.1.1\Settings.StyleCop'被拒绝。
如果我以管理员身份运行 VS,我可以编辑该文件,但 StyleCop for ReSharper 似乎无法识别规则更改。我已经卸载并重新安装了各个版本,但最终结果相同。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可以修改 StyleCop 安装目录中的 Settings.StyleCop 文件,但这几乎总是一个坏主意。
解决这种问题的最佳方法是修改项目目录中的Settings.StyleCop 文件。我相信当您右键单击一个项目并以这种方式打开设置时就会创建一个。
但经常发生的情况是,您发现所有项目都需要完全相同的设置,并且在您完成配置项目的手动过程之前,这些设置都是错误的。解决方法是这样的:
以正确的方式配置了单个项目后,将 Settings.StyleCop 文件向上移动一个目录。现在您已经有了解决方案的设置,而不仅仅是项目。解决方案中的所有项目现在都将具有相同的设置!这意味着现在您可以为不需要“典型”设置的任何项目创建项目级 Settings.StyleCop 文件。您甚至可以更进一步,将 Settings.StyleCop 文件移至“源代码管理根目录”(通常比解决方案级别至少高一级),现在您的所有解决方案都将具有相同的设置。
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.
注意:您将编辑默认设置,这些设置将应用于运行此 StyleCop 安装的所有代码。
Note: You are about to edit the default settings which are applied to all code on which this installation of StyleCop is run.
这与 StyleCop 无关。由于您尝试编辑 Program Files 文件夹中的某些内容,因此您受到 Windows 安全性的限制。默认情况下,StyleCop 的设置使您永远不需要编辑该文件。
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.
所有其他答案似乎都在告诉您“不要这样做”,但如果您确实希望此功能发挥作用,正如 Jason 回答的那样,这是 Windows 中的一项安全功能阻止了您。
修复方法:“以管理员身份”运行 Visual Studio 以使该错误消失并允许 Visual Studio 将文件保存在程序文件目录中。
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.