core icon indicating copy to clipboard operation
core copied to clipboard

Can't run code analysis using MSBuild for .NET Core 2.0 / .NET Standard 2.0 projects

Open mizbrodin opened this issue 9 years ago • 31 comments

Hello,

I'm using Visual Studio Enterprise 2017 Preview Version 15.3.0 Preview 4.0 (VisualStudio.15.Preview/15.3.0-pre.4.0+26711.1)

When I try to run code analysis using MSBuild for any .NET Core 2.0 or .NET Standard 2.0 projects using a command like this:

msbuild /p:RunCodeAnalysis=true netcore2ClassLibrary1.csproj

I'm getting the following errors:

Running Code Analysis... MSBUILD : error : CA0055 : Could not identify platform for 'E:\Source\Temp\NetS tandardClassLibrary1\netcore2ClassLibrary1\bin\Debug\netcoreapp2.0\netcore2Clas sLibrary1.dll'. [E:\Source\Temp\NetStandardClassLibrary1\netcore2ClassLibrary1
netcore2ClassLibrary1.csproj] MSBUILD : error : CA0052 : No targets were selected. [E:\Source\Temp\NetStandar dClassLibrary1\netcore2ClassLibrary1\netcore2ClassLibrary1.csproj] Code Analysis Complete -- 2 error(s), 0 warning(s)

Is this an expected behaviour? If yes, is there any other way to run code analysis for .NET Core/Standard 2.0 projects from a command line and produce the same kind of CodeAnalysisLog.xml file which is produced by MSBuild for .NET Framework projects? (I need it for our CI, for a solution which consists of a large set of old .NET Framework projects and some new .NET Standard projects as well)

Thanks Max

mizbrodin avatar Jul 19 '17 10:07 mizbrodin

@mizbrodin I have this problem, too,but I think you can use jetbrains rider instead。did you solved the problem?

mokeyish avatar Jul 23 '17 01:07 mokeyish

@mokeyish I don't have a solution for this problem yet. Our company doesn't have a license for JetBrains Rider and, at the moment, I don't know anything about this IDE and its build tools. We have Visual Studio Enterprise licenses as part of our MSDN Subscription and I'd prefer to be able to use MSBuild for running code analysis in our CI build configuration as we do it for other projects.

mizbrodin avatar Jul 24 '17 10:07 mizbrodin

Hi All, We are facing similar issue. Any workaround or solution, Also I additional observation, while compile with "netstandard2.0" as "TargetFramework", generated assembly Platform Target coming as Unknown while with "netstandard1.4" its coming as "Windows Runtime".

ShrenikOne avatar Aug 17 '17 10:08 ShrenikOne

Same issue here. It seems to me static code analysis is very fuzzy, or I just used to the existing full framework FxCop solution

CFlatWouldbeMinor avatar Aug 28 '17 07:08 CFlatWouldbeMinor

Same issue here.

nelsonmorais avatar Aug 31 '17 22:08 nelsonmorais

Same problem.

skorunka avatar Sep 06 '17 10:09 skorunka

same issue here.

sindamnataraj avatar Sep 06 '17 20:09 sindamnataraj

I have Visual Studio 2017 (15.2) and a .NetStandard core library project.

  • If the project is targeted for 1.4 and I run MSBuild.exe then everything works
  • If the project is targeted for 1.5 and I run MSBuild.exe then I get this error: MSBUILD : error : CA0055 : Coult not identify platform for "...dll path..."

FarisFAhmed avatar Sep 07 '17 12:09 FarisFAhmed

Are there any plans to address this? Any other options for running FxCop against .NET core projects?

csano avatar Oct 05 '17 17:10 csano

I have a feeling that Microsoft will not continue to support FxCop. Rather, it's expected that you install Microsoft.CodeAnalysis.FxCopAnalyzers NuGet package to your solution and it will run the code analysis via Roslyn API. Actually, they are cooler than FxCop as they:

  • work quicker;
  • provide feedback instantly (highlight errors while you are typing);
  • provide quick fixes.

See more detail here: https://github.com/dotnet/roslyn-analyzers.

Notice, not all the analyzers have been already ported, so it might still make sense to run code analysis for the supported frameworks (e.g. net 452).

zvirja avatar Oct 05 '17 21:10 zvirja

@zvirja Do you know if the Nuget package respects the CodeAnalysis MSBuild configuration settings like <RunCodeAnalysis>false</RunCodeAnalysis>, CodeAnalysis dictionarys and the ruleset files?

jahmai-ca avatar Oct 05 '17 22:10 jahmai-ca

I've used this package in the AutoFixture project and it seems to respect everything you mentioned.

zvirja avatar Oct 05 '17 22:10 zvirja

@zvirja is correct. The path forward is the Microsoft.CodeAnalysis.FxCopAnalyzers NuGet package. A large portion of the rules have been moved over to analyzers. FXCop was a solution implemented before the richness of the new C# compiler existed.

Petermarcu avatar Oct 05 '17 22:10 Petermarcu

Thanks all I'll give the package a try today.

jahmai-ca avatar Oct 05 '17 22:10 jahmai-ca

Sounds good. I'm going to close this for now but we can re-open this if it doesn't work.

Petermarcu avatar Oct 05 '17 22:10 Petermarcu

Please let me know Is this CA0055 and CA0052 issues got resolved for .Net Core 2.0 (netcoreapp2.0) projects?

Asking this because I'm still getting these errors when enabled our .Net Core 2.0 projects to use code analysis ruleset which are defined for our projects and trying to build from Visual Studio 2017 (updated to 15.3.5 version) and by using MSBuild command.

As per this conversion thread, I've installed Nuget package of Microsoft.CodeAnalysis.FxCopAnalyzers to our .net core 2.0 projects, but still getting CA0055 and CA0052 errors. Please help me out to resolve these issues which are blocking our builds.

dvm-2k1 avatar Oct 09 '17 06:10 dvm-2k1

@dvm-2k1 I opened an issue for you here: https://github.com/dotnet/roslyn-analyzers/issues/1313

Thats is the best place to get help for that specific issue.

Petermarcu avatar Oct 09 '17 17:10 Petermarcu

same here.

msd-kharazi avatar Feb 24 '18 11:02 msd-kharazi

@Petermarcu has anyone committed to fixing this issue?

Why is this issue closed? It's still a problem.

The other closed issue says that we need to install a NuGet package and compile at the command line.

Is anyone actually bothering to fix the problem inside Visual Studio?

MelbourneDeveloper avatar Mar 01 '18 22:03 MelbourneDeveloper

This is still an issue.

AlexanderJ-ULabs avatar Mar 16 '18 21:03 AlexanderJ-ULabs