5

This seems a pretty straightforward thing to do, but I cannot find relevant information. In Visual Studio is very easy to calculate code metrics for all projects and I would like to do the same during a build pipeline in Azure DevOps.

Has anyone done something like this?

Albert T
  • 61
  • 2

2 Answers2

0

In azure devops, you can review code coverage results. The results can be viewed and downloaded on the Code coverage tab.

  • Publish Code Coverage Results publishes code coverage results to Azure Pipelines or TFS, which were produced by a build in Cobertura or JaCoCo format.
  • Built-in tasks such as Visual Studio Test, .NET Core, Ant, Maven, Gulp, Grunt, and Gradle provide the option to publish code coverage data to the pipeline.

Here are some documents you can refer to:

In addition, you can get code analysis through SonarCloud integrated with Azure devops. SonarCloud is a cloud-based code quality and security service. Here is the lab you can follow.

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
0

You can generate code metrics by adding the Microsoft.CodeAnalysis.Metrics nuget and building with the parameter that target the "Metrics" build, this will store the results in an xml file.

msbuild /t:Metrics

If you're building a solution with multiple projects, you have to add the nuget to every project otherwise the build will fail because the Metrics target won't be present for the other projects. The build will produce one xml file per project.

You can also use the metrics command line tool from the roslyn analyzer repository.

See https://learn.microsoft.com/en-us/visualstudio/code-quality/how-to-generate-code-metrics-data?view=vs-2022

JMG
  • 111
  • 2
  • 3