我正在使用FxCopCmd工具进行静态代码分析.由于我们已经拥有庞大的代码库,因此我们使用FxCop附带的baseline.exe工具为现有问题奠定了基础.
我观察到如果我向我的C#类添加一个新方法,那么GlobalSuppression.cs文件中的一些抑制消息就会停止工作,而我得到的问题是我没有触及的代码.
例:
namespace ConsoleApplication1
{
class Program
{
public async Task<string> method1()
{
string a = "";
a.Equals("abc", StringComparison.InvariantCultureIgnoreCase);
return a;
}
static void Main(string[] args)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
这会引发以下错误:
CA1031:Microsoft.Design:修改'Program.d__0.MoveNext()'以捕获比'Exception'更具体的异常或重新抛出异常
为了抑制'CA1309 UseOrdinalStringComparison'问题,我在GlobalSuppression.cs文件中添加了以下抑制消息
[module:SuppressMessage("Microsoft.Globalization","CA1309:UseOrdinalStringComparison",Scope ="member",Target ="ConsoleApplication1.Program.d__0.MoveNext()",MessageId ="System.String.Equals(System.String, System.StringComparison)",Justification =""))]
但是如果我在类中再添加一个方法,那么这个抑制消息就会停止工作.这是因为method1是异步的,所以在编译的代码中创建了一个新类(参考这个)(<method1>d__0在第一种情况下).但是当我在method1之前添加另一个方法时,则会在编译代码中创建新类<method1>d__1.因此,不应用抑制消息,并且FxCop再次开始在代码中显示错误.
有没有办法永久抑制异步方法的FxCop错误?
我正在使用C#开发项目。现在,我已经设置了Hudson服务器,并且在服务器上安装了.Net 4 Framework和Windows SDK 7.1。
该项目成功构建,但是当我使用以下命令启动FxCop时:
"C:\Program Files (x86)\Microsoft FxCop 1.35\fxcopcmd.exe" /file:CommonServiceTool\bin\Release /out:fxcop-result.xml
Run Code Online (Sandbox Code Playgroud)
它加载所有.dll规则文件,然后发生以下异常:
Using system files at: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319.
Could not resolve reference to PresentationFramework.
Could not resolve reference to PresentationCore.
Could not resolve reference to WindowsBase.
12 exceptions occurred while loading Project1.
00) Could not resolve type reference: [PresentationFramework]System.Windows.StartupEventArgs.
01) Could not resolve type reference: [PresentationFramework]System.Windows.Window.
02) Could not resolve type reference: [PresentationFramework]System.Windows.Controls.HeaderedContentControl.
03) Could not resolve type reference: [PresentationCore]System.Windows.Input.ICommand.
04) Could not resolve member reference: System.Windows.ThemeInfoAttribute::.ctor.
... and …Run Code Online (Sandbox Code Playgroud) 我在TeamCity 8.0.6(build 27767)中添加了一个Build Step,以针对特定的c#项目程序集执行FxCop.
当使用MinimumRecommendedRules设置从VS 2013中运行FxCop时,我没有得到任何错误或警告(我将它们全部修复).
现在我想在TeamCity中进行连接.要限制规则,我将指定命令行属性,如下所示:
/ruleSet:=MinimumRecommendedRules.ruleset /rulesetdirectory:'FxCop\Rule Sets'
Run Code Online (Sandbox Code Playgroud)
(rulesetdirectory参数指向源树中包含标准规则集文件夹的完整内容的位置)
但是,这没有所需的行为,运行FULL规则集,我得到如下错误:
FxCop警告:关键字= CA0063种类=引擎类型= Microsoft.FxCop.Sdk.FxCopException*无法加载规则集文件"MinimumRecommendedRules.ruleset"或其依赖规则集文件之一.
这是TeamCity生成的命令行:
[17:32:29]开始:"C:\ Program Files(x86)\ Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe"/ forceoutput/ignoregeneratedcode /ruleSet:=MinimumRecommendedRules.ruleset"/ rulesetdirectory:'FxCop\Rule Sets'"/ f:dal\bin\release\MyDAL.dll /out:C:\TeamCity\buildAgent\temp\buildTmp\fxcop-output-1891867450083417003\fxcop-result.xml
谁能发现什么是错的?
前一段时间使用MSBuild任务,并找到了一些关于能够排除特定规则的文档,例如-Microsoft.Design#CA2210.MSBuild任务将其转换为/rule:-Microsoft.Design#CA2210.
我们现在在TeamCity中使用FXCop构建运行器,并将该参数添加到其他命令行参数中失败:
无法加载规则文件'-Microsoft.Design#CA2210; -Microsoft.Design#CA1020':无法找到指定的文件.
看来这个论点是指定规则集,而不是单个规则.可以这样做吗?