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

时间:2022-09-01 07:31:58

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?

我在Visual Studio 2013(c#代码)中有一个解决方案,它引用了我在NuGet(ICSharpCode.SharpZipLib)中添加的第三方程序集。当我在解决方案上运行“代码分析”时,我会收到来自第三方程序集的大量警告。我怎么告诉VS我只想从我的代码中获取代码分析建议?

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.

我很确定这些错误来自于库本身,而不是我对它的使用。共有32个问题,例如

CA2237: Mark ISerializable types with SerializableAttribute.

CA2237:使用SerializableAttribute标记ISerializable类型。

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

我使用ILMerge捆绑到单个可执行文件中你认为这会混淆代码分析吗?

1 个解决方案

#1


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忽略代码中的命名空间或类型。使用ILMerge时,SharpZipLib基本上成为代码的一部分,因为它已合并到您的程序集中。

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

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

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.

其他解决方案将提到将[GeneratedCode]属性放在您想要排除的类上,但是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 2015中,Code Analysis使用新的Roslyn Engine处理源代码,这可能会解决问题,因为它甚至在编译之前就进行了分析,因此不会受到使用IlMerge的影响。

#1


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忽略代码中的命名空间或类型。使用ILMerge时,SharpZipLib基本上成为代码的一部分,因为它已合并到您的程序集中。

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

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

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.

其他解决方案将提到将[GeneratedCode]属性放在您想要排除的类上,但是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 2015中,Code Analysis使用新的Roslyn Engine处理源代码,这可能会解决问题,因为它甚至在编译之前就进行了分析,因此不会受到使用IlMerge的影响。