如何在 Azure Devops 中安装 Cobertura?

How to install Cobertura in azure Devops?

我在 Azure devops 中有一个 .net 核心 CI。

成功 运行 我的单元测试后,我想使用 ReportGenerator 生成并显示代码覆盖率,基于这篇文章:

https://www.meziantou.net/computing-code-coverage-for-a-dotnet-core-project-with-azure-devops-and-coverlet.htm

部分 YAML:

- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Build.SourcesDirectory)/**Tests/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines;Cobertura
 displayName: Create Code coverage report

这给了我以下错误:

...line 2: Cobertura: command not found

通过从 reporttypes 中删除 Cobertura,没有错误,但是没有要显示的报告。

如何安装或启用 Cobertura?

通过从报告类型中删除 HtmlInline_AzurePipelines,它起作用了

这样你就跳过了一个参数选项。根据文档,您可以尝试使用 " 包装该选项,如下所示:

    - script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Build.SourcesDirectory)/**Tests/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage "-reporttypes:HtmlInline_AzurePipelines;Cobertura"
 displayName: Create Code coverage report

如果不跳过它,这应该也能正常工作。