如何在本地暂时禁用代码分析?
在这里,我们在本地和构建服务器上运行一组 Visual Studio 2008 的 CA 规则。为了签入,我们的 CA 规则必须与服务器策略匹配。然而,我正在开发一个包含多个项目的大型解决方案。启用 CA 规则后,在发布模式下构建项目需要很长时间,但这在创建或编辑单元测试时是必要的。这使得单元测试成为一项痛苦的任务。我想做的是有一种快速的方法(比遍历所有项目来禁用 CA 更快)在开发期间禁用 CA 规则,然后在签入之前重新启用它们。有谁知道这是否可能?
Here, we run a set of Visual Studio 2008's CA rules both locally and on the build server. In order to check in, our CA rules must match the servers policy. However, I work on a large solution with several projects. Building the project in release mode takes a long time with the CA rules enabled, but this is necessary when creating or editing unit tests. This makes working with unit tests a painful task. What I'd like to do is to have a quick way (quicker than going through all projects to disable CA) to disable the CA rules during development, and then re-enable them on before checking in. Does anyone know if this is possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常为此在解决方案级别创建一个“Debug No FxCop”构建配置,项目内配置之间的唯一区别是 Graham 已经提到的 RunCodeAnalysis 属性。为此使用构建配置可以让您在想要在 CA 和非 CA 模式之间切换时避免重新加载解决方案。
I usually create a "Debug No FxCop" build configuration at the solution level for this, with the only difference between the within-project configurations being the RunCodeAnalysis property that Graham has already mentioned. Using a build configuration for this will allow you to avoid reloading your solution when you want to switch between CA and non-CA modes.
项目文件(C# 为 *.csproj)包含一个控制是否运行代码分析的元素 -
true
。 (您可以通过在文本编辑器中打开项目文件,或在 Visual Studio 中卸载项目然后选择“编辑”来查看这一点。)您可以编写一个脚本(例如使用 PowerShell)来迭代所有项目文件,选择上面的元素带有 XPath,并切换它的值(即
true
到false
,反之亦然)。这个问题可能有用。
The project file (*.csproj for C#) contains an element that controls if Code Analysis will be run -
<RunCodeAnalysis>true</RunCodeAnalysis>
. (You can see this by opening the project file in a text editor, or Unloading the project in Visual Studio and then selecting Edit.)You could write a script (e.g. using PowerShell) that would iterate through all of the project files, select the above element with an XPath, and toggle the value of it (i.e.
true
tofalse
and vice-versa).This question could be of use.