【发布时间】:2014-09-08 08:53:34
【问题描述】:
我想将 Stylecop 警告视为错误,但它对我不起作用。
我的项目配置为将警告视为错误,如果我使用真正的“编译器警告”进行构建,它确实会显示编译器错误。但是对于“Stylecop 警告”,它只会显示一个编译器警告。
因此,当出现 Stylecop 警告时,我对 TeamCity 的签入令人烦恼地不会破坏 CI 构建。
我正在使用带有 Stylecop 4.7.49 的 VS2013。
我的设置:
-
项目 -> 属性 -> 构建
- 警告级别:4
- 禁止警告:1591
- 将警告视为错误:全部
-
项目 -> Stylecop 设置 -> 选项
- 将违规视为错误:已选中
正确中断构建的示例代码,包含真正的编译器警告:
using System;
namespace CodeUsageTest
{
public class CodeUsage
{
private string fff()
{
int nobodyLovesMe; //CS0168
return "";
}
}
}
构建输出:
1>------ Build started: Project: CodeUsageTest, Configuration: Debug Any CPU ------
1>D:\Sandbox\CodeUsageTest\CodeUsage.cs(9,17,9,30): error CS0168: Warning as Error: The variable 'nobodyLovesMe' is declared but never used
========== Build: 0 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========
不会破坏构建的示例代码(虽然我想要它),包含 stylecop 警告:
using System;
namespace CodeUsageTest
{
public class CodeUsage
{
private string fff() //SA1300
{
return ""; //SA1122
}
}
}
构建输出:
1>------ Build started: Project: CodeUsageTest, Configuration: Debug Any CPU ------
1>D:\Sandbox\CodeUsageTest\CodeUsage.cs(7,1): warning : SA1300 : CSharp.Naming : method names begin with an upper-case letter: fff.
1>D:\Sandbox\CodeUsageTest\CodeUsage.cs(9,1): warning : SA1122 : CSharp.Readability : Use string.Empty rather than "".
========== Build: 1 succeeded, 0 failed, 3 up-to-date, 0 skipped ==========
【问题讨论】:
-
这是一个编译器设置。请改用
<StyleCopTreatErrorsAsWarnings>属性。顺便说一句,第一个谷歌点击。 -
更糟的是,有时警告似乎被视为错误,但在VS“错误列表”窗口中没有报告:developercommunity.visualstudio.com/content/problem/61023/…。跨度>
标签: c# visual-studio visual-studio-2013 compiler-warnings stylecop