SDK式项目目标.NET框架中的FXCOP输出中缺少文件名和行号

发布于 2025-02-05 16:12:21 字数 1171 浏览 1 评论 0原文

我们在解决方案中经常使用FXCOP代码分析(“遗产”)。我们正在打开许多Microsoft规则,并且还为我们想要检查的代码方面编写了大量我们自己的FXCOP风格的分析仪。这一切都在“旧”风格的Visual Studio C#项目中运行良好,该项目针对各种.NET框架版本(当前4.7.2)。

但是,当同一项目移植到新的“ SDK式”格式时,并通过具有Net472来定位目标.NET Framework 4.7.2,我们通过添加True来启用代码分析,我们遇到了一个问题。我们的自定义FXCOP规则似乎仍然可以正常工作并输出警告,但是在“错误列表”窗口中,“文件”列下没有文件名,并且“行”列下总是有第1行。因此,我们可以看到警告消息,但是不可能双击警告并找出与警告相关的源代码中的位置 - 这使整个代码分析无用。当我切换到“输出/构建”窗口时,我还可以按线路看到警告,但是此处也缺少文件名/行号信息。

我知道以下事实:

We used FXCOP code analysis ("legacy") a lot in our solution. We are turning on many Microsoft rules, and also have written a large set of our own FXCOP-style analyzers for aspects of code that we wanted to have checked. And it all worked quite well in the "old" style Visual Studio C# projects, aimed at various .NET Framework versions (currently 4.7.2).

When, however, the same project is ported to the new "SDK-style" format, and made to target .NET Framework 4.7.2 by having net472, and we enable the code analysis by adding true, we run into a problem. Our custom FXCOP rules appear to still work well and output their warnings, but in the Error List window, there are no file names under the "File" column, and there is always line 1 under the "Line" column. Consequently, we can see the warning messages, but it is impossible to double-click on the warning and figure out the location in the source code the warning related to - which makes the whole code analysis useless. When I switch to the Output/Build window, I can also see the warnings there line by line, but the file name/line number information is missing here as well.

I am aware of the followings facts:

  • That Microsoft has ported many or all their FXCOP rules to Roslyn (".NET Analyzers") and they can/should now be used. However I need to use our own rules, not just the Microsoft rules. Rewriting our rules to Roslyn may be the right solution in the long run, but it would be a huge undertaking in short- or mid-term.

  • That FXCOP (legacy) analysis is not supported in .NET Core and .NET Standard projects in VS (as per https://learn.microsoft.com/en-us/visualstudio/code-quality/static-code-analysis-for-managed-code-overview?view=vs-2022 ). My project is not, however, for .NET Core or .NET Standard, as I described above. It is for .NET Framework 4.7.2 - the problem seems to be in the fact that it is the SDK-style. And the reason I need it in this format is because it is the format that I will then use to port to .NET Core/.NET 6+.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久伴你 2025-02-12 16:12:21

我发现了一个部分解决该问题的方法。 FXCOPCMD(此使用)之所以发出文件名和行号,是因为默认情况下,在SDK式项目中,PDB文件格式设置为Portable。 FXCOPCMD不了解便携式PDB。该解决方案是在Visual Studio Project Properties中,将“调试符号”设置为“ PDB文件,当前平台”。 .CSPROJ文件中的相应设置是

 <DebugType>full</DebugType>

在进行此更改之后,文件名和行号出现在文本输出中以及其错误列表中的列中,并且可以单击输出或错误列表中的警告,以及您将被带到来源的正确位置。

尚未起作用的是:错误列表中的“抑制...”上下文菜单命令仍未显示。

I have a found a partial solution to the problem. The reason FxCopCmd (which is used by this) does not emit file names and line numbers is because by default, in SDK-style projects, the PDB file format is set to portable. FxCopCmd does not understand the portable PDB. The solution is in Visual Studio project properties, set the "Debug symbols" to "PDB file, current platform". The corresponding setting in the .csproj file is

 <DebugType>full</DebugType>

After making this change, the file names and lines numbers appear in the text output, and in their columns in Error List, and it is possible to click on warnings in the output or Error List, and you will be taken to the right place in the source.

What does not work yet: The "Suppress..." contextual menu commands in the Error List still do not appear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文