[英]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.