且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Visual Studio 2013中,如何将代码分析限制为我的代码而不是引用的程序集?

更新时间:2022-02-25 03:58:24

如果驻留在相同的二进制文件中,则无法告诉FxCop忽略代码中的名称空间或类型.使用ILMerge时,SharpZipLib实际上已成为代码的一部分,因为它已合并到程序集中.

There is no way to tell FxCop to ignore namespaces or types in your code if it lives in the same binaries. When using ILMerge, the SharpZipLib essentially becomes part of your code, as it's merged into your assembly.

要获得正确的结果,请在合并之前生成的程序集上运行FxCop.

To get proper results, run FxCop on the assembly that's generated before the merge.

其他解决方案将提到放置[GeneratedCode]属性对于您想排除的类,但是IlMerge在合并时没有选择,所以这对您没有帮助.

Other solutions will mention to put a [GeneratedCode] attribute on classes you want excluded, but IlMerge has no option to to that while merging, so that won't help you out.

在Visual Studio 2015中,代码分析使用新的Roslyn Engine处理源代码,这可能会解决该问题,因为即使在编译之前它也会进行分析,因此不会受到IlMerge的使用影响.

In Visual Studio 2015 Code Analysis works on the source code using the new Roslyn Engine, which will solve the issue probably, as it does the analysis even before compilation and as such will not be impacted by your use of IlMerge.