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

2

9

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.

Kafka answered 7/10, 2017 at 6:15 Comment(1)
Please respond to this question if you have any solutions or suggestions as it is blocking our build to overcome these code analysis issues on our ASP.Net Core 2.0 migrated applications.Kafka
S
13

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

Somerset answered 13/10, 2017 at 14:17 Comment(4)
Just to clarify, this is just a workaround to get it to build - which requires you to disable code analysis, not a solution.Debark
The flavor of Code Analysis he's using (FxCopCmd.exe) isn't supported for .NET Core 2.0 because it's a legacy tool. The new tool to be used going forward for .NET Core 2.0 is FxCopAnalyzers. I'll update my answer to reflect that.Somerset
Just to be really clear, this is the solution to using Code Analysis with .NET Core. It only disables the old version of Code Analysis. The new version (that works with .NET Core) will still function.Somerset
It seems that if you want to use SonarQube analysis files, you need to include the NuGet SonarAnalyzer.CSharp For more details see : github.com/StefH/SonarLintTestEmbassy
E
0

Set 'RunCodeAnalysis' element to false from your .csproj file.

Emanate answered 3/4, 2023 at 13:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.