简体   繁体   English

.Net 框架项目上的 Visual Studio 代码分析

[英]Visual Studio Code Analysis on .Net Framework Projects

I am attempting to enable code analysis via Nuget for an existing.Net Framework 4.72 Web Application.我正在尝试通过 Nuget 为现有的.Net Framework 4.72 Web 应用程序启用代码分析。 To be frank, the documentation has me confused as to which packages to install.坦率地说,文档让我对要安装哪些软件包感到困惑。

I have installed Microsoft.CodeAnalysis.NetAnalyzers via nuget.我已经通过 nuget 安装了Microsoft.CodeAnalysis.NetAnalyzers

The following is in my csproj file:以下是在我的 csproj 文件中:

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    ...
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <AnalysisMode>AllEnabledByDefault</AnalysisMode>

This code is loaded with problems, but I only the following two items are listed:这段代码加载有问题,但我只列出了以下两项:

warning CA2237: Add [Serializable] to ParseException as this type implements ISerializable
warning CA1001: Type 'Repository' owns disposable field(s) '_context' but is not disposable

Are there other packages to load?还有其他要加载的包吗?

If you're seeing CA*** diagnostics, then it's working.如果您看到CA***诊断程序,那么它正在工作。

You can turn on more diagnostics in your projects via the "Dependencies" tree (expand the analyzers node).您可以通过“依赖项”树(展开分析器节点)在项目中打开更多诊断。

Also, you have to add this PackageReference and associated properties to each project in your solution.此外,您必须将此PackageReference和相关属性添加到解决方案中的每个项目。 You might like to do this in a Directory.Build.props file.您可能希望在Directory.Build.props文件中执行此操作。

Why do you think you should be seeing more diagnostics?为什么你认为你应该看到更多的诊断?

The answer is in the References\Analyzers node of the.Net Framework project.答案在 .Net Framework 项目的References\Analyzers节点中。 I can verify the presence of Microsoft.CodeAnalysis.NetAnalyzers.我可以验证 Microsoft.CodeAnalysis.NetAnalyzers 的存在。 The rules now default to minimum, which means there are only 2 issues in my app.规则现在默认为最小,这意味着我的应用程序中只有 2 个问题。

Right click on Analyzers|Open Active Ruleset... and the rules can be customized.右键单击分析器|打开活动规则集... ,可以自定义规则。

It did not help this legacy project is a little wonky.它没有帮助这个遗留项目有点不稳定。 I had to make a new project and pull in the Analyzer peices.我不得不创建一个新项目并引入分析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Studio Code中调试多个ASP.NET Core项目 - Debug multiple ASP.NET Core projects in Visual Studio Code Visual Studio中的代码分析问题 - Code analysis issue in Visual Studio Maven + .NET + Sonar v4.5.1 + Visual Studio项目的分析引导程序 - Maven + .NET + Sonar v4.5.1 + Analysis Bootstrapper for Visual Studio Projects Visual Studio项目的.NET类? - .NET classes for Visual Studio projects? Visual Studio Code 中没有 C# 代码分析 - No C# Code Analysis in Visual Studio Code Visual Studio Code .NET 框架在通过统一启动时不起作用 - Visual Studio Code .NET framework not working when launched through unity Visual Studio Debugger没有进入.NET框架源代码 - Visual Studio Debugger not stepping into .NET framework source code 在Visual Studio 2012中调试.NET Framework源代码? - Debug .NET Framework Source Code in Visual Studio 2012? 无法在 .NET 5 和 Visual Studio Code 中引用 Entity Framework Core - Can't reference Entity Framework Core in .NET 5 and Visual Studio Code 如何将所有解决方案项目 .Net framework 4.5.1 升级到 4.8 Visual Studio 2019 - How to upgrade all solution projects .Net framework 4.5.1 to 4.8 Visual Studio 2019
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM