将 StyleCop 集成到 NAnt 构建脚本中

发布于 2024-08-26 09:51:47 字数 222 浏览 15 评论 0原文

有没有办法将 StyleCop 集成到 NAnt 脚本中,这样如果样式违规太多,构建就会失败?

StyleCop 似乎没有 NAnt 任务,但我们找到了 StyleCopCmd。然而,这似乎只生成一个 XML 文件作为我们必须解析的输出。有更简单的解决方案吗?

Is there a way to integrate StyleCop in a NAnt script such that the build fails if there are too many style violations?

There doesn't seem to be a NAnt task for StyleCop, but we've found StyleCopCmd. However this only seems to generate an XML file as output that we'd have to parse. Is there some easier solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰魂雪魄 2024-09-02 09:51:47

是的 - 我上周就在工作中设置了 StyleCop! (我没有使用 StyleCop 以外的任何东西...)

基本上,我需要做的就是让 StyleCop 在 Visual Studio 2008 中工作,确保我的代码库通过了所有警告,然后更改了.csproj 文件使其结果显示错误,而不是警告。

然后,当我运行相同的 NAnt 脚本时,构建应该像以前一样通过。

但诀窍是返回到您的代码,违反其中一条规则,但退出 VS2008,然后运行您的构建脚本。该代码应该不符合 StyleCop 规则并导致您的构建失败。

希望这有帮助!

Yes - I set StyleCop up at work just last week! (I didn't use anything other than StyleCop...)

Basically, all I needed to do, was to get StyleCop working in Visual Studio 2008, making sure that my codebase passed all of it's warnings, and then changed the setting in the .csproj file to make it's findings Errors, instead of Warnings.

Then, when I ran the same NAnt script, the build should pass as before.

But the trick is to go back into your code, violate one of the rules but quit out of VS2008 and then run your build script. The code should fail the StyleCop rule and fail your build.

Hope this helps!

吾性傲以野 2024-09-02 09:51:47

您根本不需要对 NAnt 做任何事情。

您只需执行两件事:

  • 向每个 .csproj 文件添加两行,
  • 包括项目中的 StyleCop 文件并将它们放入源代码管理中

您可以在此处找到该过程的更详细描述:
http://blogs.msdn .com/b/sourceanalysis/archive/2008/05/24/source-analysis-msbuild-integration.aspx

之后,StyleCop 将在每个构建上运行,无论在什么机器上(并且无需在每台机器上安装它)机),无论构建是如何启动的(从 Visual Studio、从 MSBuild...)。

因此,只要 NAnt 调用 MSBuild 来实际构建解决方案,StyleCop 也会运行。

You don't need to do anything with NAnt at all.

You just have to two things once:

  • add two lines to every .csproj file
  • include the StyleCop files in your project and put them into source control

You can find a more detailed description of the process here:
http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/24/source-analysis-msbuild-integration.aspx

After that, StyleCop will run on EVERY build, no matter on what machine (and without installing it on each machine) and no matter how the build was started (from Visual Studio, from MSBuild...).

So, as long as NAnt calls MSBuild to actually build the solution, StyleCop will run as well.

静赏你的温柔 2024-09-02 09:51:47

如果您不想通过 MSBuild 执行此操作,可以使用 StyleCopCLI http://stylecopcli.sourceforge.net /

In case you don't want to do it thru MSBuild, you can do it using StyleCopCLI http://stylecopcli.sourceforge.net/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文