简体   繁体   English

VS2017中dotnet核心项目的代码分析

[英]Code analysis for dotnet core project in VS2017

I want add code analysis (FxCop, not StyleCop) for my dotnet core project, it is targeting netcoreapp1.1 framework. 我想为我的dotnet核心项目添加代码分析(FxCop,而不是StyleCop),它的目标是netcoreapp1.1框架。 I know that FxCop is built in MSBuild, but when I enabled it, I kept getting error: 我知道FxCop是在MSBuild中构建的,但是当我启用它时,我不断收到错误:

1>MSBUILD : error : CA0055 : Could not identify platform for 'C:\\Dev\\easycube\\EasyCube.Authentication\\bin\\Debug\\netcoreapp1.1\\EasyCube.Authentication.dll'. 1> MSBUILD:错误:CA0055:无法识别'C:\\ Dev \\ easycube \\ EasyCube.Authentication \\ bin \\ Debug \\ netcoreapp1.1 \\ EasyCube.Authentication.dll'的平台。 1>MSBUILD : error : CA0052 : No targets were selected. 1> MSBUILD:错误:CA0052:未选择任何目标。

Then I found that there is Nuget package for dotnet core analyzer Microsoft.NetCore.Analyzers, but I do not know how to use it. 然后我发现有针对dotnet核心分析器Microsoft.NetCore.Analyzers的Nuget包,但我不知道如何使用它。 Anyone know how to set it up on the project? 有谁知道如何在项目上进行设置?

Thank you. 谢谢。

.Net Core does not support Code Analysis the old way. .Net Core不支持Code Analysis旧方法。

You need the Nuget Package Microsoft.CodeAnalysis.FxCopAnalyzers . 您需要Nuget包Microsoft.CodeAnalysis.FxCopAnalyzers Add it to your project and you will get the warnings. 将它添加到您的项目中,您将收到警告。 See here for some more Analyzers . 请参阅此处了解更多分析仪

If you try to run the old code analysis on a solution with .Net Core project you can switch it off for every project (see here ) by adding a custom target to the end of the project files: 如果您尝试在.Net Core项目的解决方案上运行旧代码分析,则可以通过在项目文件末尾添加自定义目标来为每个项目(请参阅此处 )关闭它:

<Target Name="IgnoreRunCodeAnalysis" Condition=" '$(RunCodeAnalysis)' == 'true' " BeforeTargets="RunCodeAnalysis">
    <Message Importance="normal" Text="Set RunCodeAnalysisOnThisProject to false" />
    <PropertyGroup>
        <RunCodeAnalysisOnThisProject>false</RunCodeAnalysisOnThisProject>
    </PropertyGroup>
</Target>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM