11

I have a setup where Visual Studio 2010 runs test coverage analysis and it's output is absorbed by NDepend during an integration build.

A few assemblies contain generated code that needs to be ignored by NDepend.
Is there a way to do this? Preferably an entire namespace.

4

2 回答 2

5

Code Query and Rule over LINQ (CQLinq)确实提供了一种忽略生成代码的工具。

有一个方便的预定义域,名为JustMyCode,类型为ICodeBaseView

JustMyCode表示 CQLinq 的一种工具,用于从 CQLinq 查询结果中消除生成的代码元素。例如,以下查询将仅匹配不是由工具(如 UI 设计器)生成的大型方法:

from m in JustMyCode.Methods where m.NbLinesOfCode > 30 select m

生成的代码元素集由以 CQLinq 关键字notmycode为前缀的 CQLinq 查询定义。例如,下面的查询匹配源文件中定义的方法,其名称以".designer.cs" 结尾

notmycode from m in Methods where
  m.SourceFileDeclAvailable && 
  m.SourceDecls.First().SourceFile.FileName.ToLower().EndsWith(".designer.cs")
select m

CQLinq 查询运行器在依赖 JustMyCode 的查询之前执行所有notmycode查询,因此域JustMyCode被定义一次。显然,如果notmycode查询依赖于JustMyCode域,CQLinq 编译器会发出错误。

有 4 个默认的notmycode查询,可轻松适应您的需要。请注意,命名空间没有默认的notmycode查询,但您可以创建自己的查询:

于 2011-09-13T09:16:37.630 回答
1

Found this in the "Quick summary of methods to refactor"

// Here are some ways to avoid taking account of generated methods.
!( NameIs "InitializeComponent()" OR
   // NDepend.CQL.GeneratedAttribute is defined in 
   // the redistributable assembly $NDependInstallDir$\Lib\NDepend.CQL.dll
   // You can define your own attribute to mark "Generated".
   HasAttribute "OPTIONAL:NDepend.CQL.GeneratedAttribute") 

But that doesn't address the need to modify every CQL query to ensure they all ignore the generated code.

于 2011-09-30T00:22:08.550 回答