在Visual Studio 2013中,如何将代码分析限制为我的代码而不是引用的程序集? [英] In Visual Studio 2013 how do I limit code analysis to my code and not to referenced assemblies?

查看:109
本文介绍了在Visual Studio 2013中,如何将代码分析限制为我的代码而不是引用的程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2013(c#代码)中有一个解决方案,该解决方案具有对我随NuGet添加的第三方程序集(ICSharpCode.SharpZipLib)的引用.当我在解决方案上运行代码分析"时,我收到来自第三方程序集的许多警告.如何告诉VS,我只需要代码中的代码分析建议?

I have a solution in Visual Studio 2013 (c# code) that has a reference to a third-party assembly that I added with NuGet (ICSharpCode.SharpZipLib). When I run the "Code Analysis" on the solution I get lots of warnings coming from the third-party assembly. How do I tell VS that I only want code analysis advice from my code?

我很确定错误来自库本身,而不是我的使用.共有32期,例如

I'm pretty sure the errors are coming from the library itself and not my usage of it. There are a total of 32 issues e.g.

CA2237:使用SerializableAttribute标记ISerializable类型.

CA2237: Mark ISerializable types with SerializableAttribute.

我正在使用ILMerge捆绑到一个可执行文件中,您认为这使代码分析感到困惑吗?

I am using ILMerge to bundle into a single executable do you think that has confused the code analysis?

推荐答案

如果驻留在相同的二进制文件中,则无法告诉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.

这篇关于在Visual Studio 2013中,如何将代码分析限制为我的代码而不是引用的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆