Version Used:
15.8 Preview 3
Steps to Reproduce:
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.
Make note, we recently changed Project.Kind to return the legacy project system which unblocked this path and Code Metrics now shows up.
@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.
Area-External means "we don't own it". We own this.
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:
---------------------------
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.
~@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 There are couple of reasons not to do your suggested change now:
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.
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.
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!
Fixed with internal VSO PR. The fix should be available in Dev16 P1.
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 https://github.com/dotnet/roslyn-analyzers/pull/1740. We also plan to provide a command line executable, such as Metrics.exe in pre-Dev15 versions, https://github.com/dotnet/roslyn-analyzers/issues/1741 tracks that work.
This error is still present for .NET Core Projects. (.net core version 2.1) (VS Version 15.8.1)
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.
See https://github.com/dotnet/roslyn-analyzers/pull/1754 for usage of Metrics.exe.
What version of visual studio is Dev16 Preview 1?
How does that equate to Visual Studio versions 15.x.x?
@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.
Most helpful comment
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!