如果有未使用的命名空间,是否有任何工具或方法可以使构建失败

Is there any tool or way to fail a build if there are unused namespaces

Visual StudioResharper 突出显示未使用的命名空间,但它们 生成任何警告,因此我们无法使用 将警告视为错误 并且项目编译良好:

Resharper 可以在边栏中显示警告,但我认为可以配置为显示错误。

StyleCop 也许也可以做到这一点。快速 google 搜索让我相信 IDE0005 可以做到这一点。

我找到了 CI 的解决方案(持续集成)。您可以使用 Inspections in TeamCity:

  1. 创建构建步骤Inspections (Resharper)
  2. 添加Failure ConditionsFail build on metric change(检查警告数)。

https://www.jetbrains.com/help/resharper/Detect_code_issues_in_a_build_using_ReSharper_and_TeamCity.html