Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling Code Analysis for .Net Core 2.0 project results CA0055 and CA0052 errors

Currently I'm getting CA0055 and CA0052 code analysis errors (both with Visual Studio 2017 and also by using MSBuild command) after configuring ASP.Net Core 2.0 application with custom code analysis ruleset which are defined for our projects. Tried different ways to resolve these errors by going through different solutions provided, but there was no luck. Please help us in resolving these code analysis errors...

Following are the error details

MSBUILD : error : CA0055 : Could not identify platform for 'D:\Source\Temp\WebClient\Business\bin\Debug\netco reapp2.0\Business.dll'. [D:\Source\Temp\WebClient\Business\Business.csproj] MSBUILD : error : CA0052 : No targets were selected. [D:\Source\Temp\WebClient\Business\Business.csproj] Code Analysis Complete -- 2 error(s), 0 warning(s)

Thanks, Venu Madhav.

like image 857
venu madhav Avatar asked Oct 07 '17 06:10

venu madhav


1 Answers

This error is caused by using an old version of Code Analysis with .NET Core. This old version is only for non-.NET Core applications.

The solution is to disable the old Code Analysis for .NET Core projects and install the new version of Code Analysis, which is now a NuGet package. (The reason you probably want to disable the old Code Analysis tool for your project and NOT uninstall it is so that you can still use the old Code Analysis with old .NET applications, such as .NET 4.5.)

  1. Install the Code Analysis NuGet package in one of your projects in your solution: Microsoft.CodeAnalysis.FxCopAnalyzers

    Refer to https://github.com/dotnet/roslyn-analyzers#recommended-version-of-analyzer-packages to chose the right package version based upon your Visual Studio version.

  2. Remove the RunCodeAnalysis element from your .csproj files (if it exists). This is done to disable the old legacy version of Code Analysis. The new version that you installed will still function.

Additional details are described here: https://github.com/dotnet/roslyn-analyzers/issues/1313

like image 172
Brandon S Avatar answered Oct 17 '22 17:10

Brandon S