如何根据 FXCop 警告使 TFS 构建失败
我们目前使用 TFS 2008 进行源代码控制和持续集成。
我们使用 FXCop 来检查性能和安全警告。架构师或高级开发人员在冲刺结束或交付之前运行 FX Cop。
我们希望它作为 CI 的一部分运行,如果出现警告则构建失败,最好的方法是什么?
We are currently using TFS 2008 for source control and continuous integration.
We use FXCop to check for checking performance and security warnings. The Architect or senior developer runs FX Cop at the end of a sprint or before a delivery.
We would like this to run as part of the CI and fail the build if there is a warning, what is the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您通过 MSBuild 和常规项目/解决方案进行构建,则可以将 FXCop 配置为作为每个构建(客户端和服务器)的一部分运行。在项目的属性对话框中,查看“代码分析”选项卡。请注意,这可以为调试和发布版本单独设置,因此您可以将它们设置为发布版本的错误(如果这能让开发人员的生活更轻松)。
这些 FXCop 设置允许您定义违规在构建中显示为错误而不是警告。您可能还希望启用 TFS 策略,该策略要求在签入有效之前使用一组定义的规则运行代码分析 - 这将通过强制开发人员在签入之前修复违规行为来节省一些红色构建。
我确实建议打开所有这些东西 - 如果您的目标是达到这种质量水平(这不是坏主意),那么最好尽可能多地进行预登记。
Assuming you're building through MSBuild and regular projects/solutions, you can configure FXCop to run as part of every build (both client and server). In your project's properties dialogue, look at the "Code Analysis" tab. Note that this can be set separately for debug and release builds, so you could just set them to errors for Release builds if that makes your developers' life easier.
These FXCop settings allow you to define that violations appear as errors instead of warnings in the build. You mkight also want to enable the TFS policy that requires code analysis to have been run with a defined set of rules before the checkin is valid - that'll save you some red builds by forcing developers to fix violations before checkin.
I do recommend turning all of these things on - if you're aiming for this level of quality (which is no bad idea), it's good to be doing as much as you can pre-checkin.
我一直在做类似的事情。尽管这个问题有点老了,但我希望它能对你有所帮助。
我像大多数人一样开始 - 通过创建一个调用 FxCopCmd 的构建后事件。
就我而言,我只需要一小部分代码、一些内置规则以及一些自定义规则(在 .dll 中),
为此我使用了 .fxcop 项目文件 - 按照我的方式配置它通过 GUI 需要,然后在构建后事件中将 FxCopCmd 指向项目文件。
在大多数情况下,它运作良好,但违规行为仅作为警告出现。 “将警告视为错误”选项似乎不适用于此,因此我不得不提出不同的解决方案。
最终最适合我的是基于我偶然发现的一篇博客文章。
我修改了项目文件以添加两个新事件。
我有一些 FxCop 的额外参数和内容,但其要点是:
一般流程如下:
现在,如果 FxCop 分析生成(例如)4 个规则违规,您的构建将生成 4 个警告和 1 个错误。
我希望这有帮助。
I've been working on something similar. Even though this question is a bit old, I'm hoping it will help you.
I started out like most -- by making a post-build event that calls FxCopCmd.
In my case, I wanted just a small subset of the code, some of the built-in rules, and also some custom rules (in a .dll)
I used an .fxcop project file for this -- configuring it all just how I wanted via the GUI and then pointing FxCopCmd to the project file in the post-build event.
For the most part, it worked great, but the rule violations came up only as warnings. The "Treat warnings as errors" option doesn't seem to apply to this, so I had to come up with a different solution.
What ultimately worked best for me was based on a blog post I stumbled upon.
I modified the project file to add in two new events.
I have a few extra parameters and stuff for FxCop, but the gist of it is:
The general flow is like this:
Now, if the FxCop analysis generated -- for example -- 4 rule violations, your build would generate 4 warnings and 1 error.
I hope this helps.
您可以查看代码分析功能在 Visual Studio 中,支持在持续集成环境中使用。
You could take a look at the code analysis features within Visual Studio, which is supported for use in a continuous integration environment.