Search code examples
c#visual-studiocode-metricsvisual-studio-2019

Did Visual Studio 2019 change the criteria for code metrics? I get twice as many now


I have been using Visual Studio to develop in C# and its "Calculate Code Metrics" option in Analyze -> Calculate Code Metrics.

Before migrating from VS2017 to VS2019, I changed a few libraries to target NET Standard. This made the Code Metrics crash in VS2017, not showing any metrics for the newly converted libraries.

After installing VS2019, the Code Metrics is working again. However, it shows me more than double the numbers I had before, even for small projects that were unmodified.

I checked the "release notes" section of VS2019 and did not find any mention of changes in how lines of code are calculated.

Update: I do not get exactly twice, I get slightly more than twice. The factor changes from project to project.


Solution

  • Had the same issue myself.

    Visual Studio 2017 calculates lines of code based on the IL. Visual Studio 2019 appears to be counting the lines of code in the code editor. There's a note on the Microsoft docs that says the command-line version counts lines of source code instead of IL. I suspect this is either an oversight, or perhaps they are using that command-line version inside of VS.


    Seems this was fixed in an update, as code metrics now shows "Lines of Source code" and "Lines of Executable code" as separate metrics.