Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Code Metrics on CPS project targeting .NET Core/.NET Standard displays an error #27001

Closed
davkean opened this issue May 21, 2018 · 17 comments

Comments

@davkean
Copy link
Member

davkean commented May 21, 2018

Version Used:
15.8 Preview 3

Steps to Reproduce:

  1. File -> Console App (.NET Core) or Class Library (.NET Standard)
  2. Analyze -> Calculate Code Metrics -> For [ConsoleApp]

Expected Behavior:
Succeeded

Actual Behavior:

Message: An error occurred while calculating code metrics for target file 'c:\users\davkean\Source\Repos\ConsoleApp341\ConsoleApp341\bin\Debug\netcoreapp2.0\ConsoleApp341.dll' in project ConsoleApp341. Could not identify platform for 'c:\users\davkean\Source\Repos\ConsoleApp341\ConsoleApp341\bin\Debug\netcoreapp2.0\ConsoleApp341.dll'.

Note: If you target .NET Framework from the project than it succeeds.

@davkean
Copy link
Member Author

davkean commented May 21, 2018

Make note, we recently changed Project.Kind to return the legacy project system which unblocked this path and Code Metrics now shows up.

@sharwell
Copy link
Member

@mavasani I'm changing this to Area-External as I believe it's part of CodeAnalysisPackage (StanCore). If this is not correct please change it back.

@davkean
Copy link
Member Author

davkean commented Jun 16, 2018

Area-External means "we don't own it". We own this.

@mavasani
Copy link
Contributor

mavasani commented Jul 3, 2018

Tagging @jinujoseph

The Code Metrics command handlers are currently statically hooked up with project type GUIDs, hence always show up for all C#, VB and C++ projects, until the Metrics Package gets loaded in VS (which happens when either user first attempts to calculate code metrics or opens the Code Metrics results window). Run Code Analysis command(s) on the other hand has duplicate handling in the shell and StanCore assemblies, but is dynamically setup only for legacy C# and VB project system. I talked with @jinujoseph and we are going for the following approach:

  1. For 15.8 - Gracefully fail for first attempt at "Calculate Code Metrics" for C# and VB CPS projects.
---------------------------
Microsoft Visual Studio
---------------------------
Cannot calculate code metrics because none of the selected projects support code metrics or Visual Studio is debugging an application.
---------------------------
OK   
---------------------------

Note that after the first attempt, the menu will not show up for CPS projects.

  1. For 16.0 - Hide the command by default for all C# and VB projects, so we can gather telemetry and usage info for this feature and make a call on whether to deprecate it in VS in a subsequent release and replace it with a standard analyzer/external tool to report code metrics OR continue support in VS, which would mean properly hook up all the handlers.

@davkean
Copy link
Member Author

davkean commented Jul 3, 2018

@mavasani This was the behavior before my Project.Kind change. After my change (and current builds) the behavior is exactly as described above. Strike that - I see that's what you want to do. I would prefer that instead you changed commands to use context rules that queries the project for TFMs to exclude so that the command never shows ups even when the package isn't loaded.

@davkean
Copy link
Member Author

davkean commented Jul 3, 2018

@mavasani
Copy link
Contributor

mavasani commented Jul 3, 2018

@davkean There are couple of reasons not to do your suggested change now:

  1. For long term (16.0), we want the Code metrics feature support to be uniform across project systems and TFMs. If we decide to deprecate it or remove it from VS, it will be removed for all managed projects. If not, it will be fully supported for both project systems and all TFMs. If we decided to do the latter, then we will move the code metrics implementation to be source based analysis, which should work for all managed projects. So, all the current command handler functionality for Code metrics commands will just work.
  2. Risk: My proposed fix for 15.8 is the simplest low risk fix to gracefully tell the users it is not supported for now. This fix will be reverted for 16.0 when we deprecate or properly support code metrics for all scenarios.

@davkean
Copy link
Member Author

davkean commented Jul 4, 2018

Help me understand the risk with using context based rules? Here's an example of a definition: https://github.com/dotnet/project-system/blob/master/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Packaging/ManagedProjectSystemPackage.cs#L22.

@mavasani
Copy link
Contributor

mavasani commented Jul 4, 2018

On second thought, I feel we should do nothing here in 15.8 and instead figure out the story for Code Metrics for 16.0: deprecate it or fully support it for all TFMs, especially as we are very sure that we want to deprecate binary FxCop and the FxCop analysis engine that current Code Metrics implementation is based upon in 16.0.
Current experience for CPS projects, though not ideal, neither blocks any supported feature nor leads to a crash/hang/performance issue to warrant a short term fix. @jinujoseph to make a call.

@ardalis
Copy link

ardalis commented Jul 5, 2018

I'd very much like to see Code Metrics support added for Core/Standard projects. Please consider it as a priority to include in an upcoming (soon) release, since currently behavior feels like VS is going backward, losing functionality it's had for many years/versions. Thanks!

@jinujoseph jinujoseph modified the milestones: 15.8, 16.0 Jul 24, 2018
@mavasani
Copy link
Contributor

Fixed with internal VSO PR. The fix should be available in Dev16 P1.

@mavasani
Copy link
Contributor

mavasani commented Jul 24, 2018

To clarify: With Dev16 P1, Code Metrics should work for all C# and VB projects.

Given the number of customer requests, we have also ported Code metrics related FxCop rules to analyzers with dotnet/roslyn-analyzers#1740. We also plan to provide a command line executable, such as Metrics.exe in pre-Dev15 versions, dotnet/roslyn-analyzers#1741 tracks that work.

@xt449
Copy link

xt449 commented Aug 19, 2018

This error is still present for .NET Core Projects. (.net core version 2.1) (VS Version 15.8.1)

  1. Create new .NET Core Console Application.
  2. Calculate Code Metrics.

@mavasani
Copy link
Contributor

This should work with Dev16 Preview1. Alternatively, you can build Metrics.csproj from Roslyn-analyzers repo and use the built exe to generate a code metrics report from command line.

@mavasani
Copy link
Contributor

See dotnet/roslyn-analyzers#1754 for usage of Metrics.exe.

@bearslumber
Copy link

What version of visual studio is Dev16 Preview 1?
How does that equate to Visual Studio versions 15.x.x?

@mavasani
Copy link
Contributor

@bearslumber It is not part of VS2017 (i.e. version 15.x.x or Dev15), but should be part of VS2019 (i.e., version 16.x.x or Dev16). See https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants