首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在macOS DevOps管道中运行盖子和报告生成器

在macOS DevOps管道中运行盖子和报告生成器
EN

Stack Overflow用户
提问于 2019-12-21 09:10:06
回答 2查看 843关注 0票数 0

我有一个用DotNetCore2.1编写的C#项目,我试图为它设置一个Azure管道,以便在运行macOS代理时获得代码覆盖率(我可以更改到其他代理,但理想情况下,管道与系统无关)。到目前为止,我一直试图让被子报告产生者协同工作,但是我经常遇到一些问题,比如Could not find data collector 'XPlat Code Coverage'

我想要做的是确定代码覆盖率( coverlet似乎正在这样做),并以某种方式在Azure管道中生成和显示代码覆盖率报告。

到目前为止,这是我的管道:

代码语言:javascript
复制
pool:
  vmImage: macOS-latest

variables:
  solution: 'src/MySolution.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'

steps:
- task: DotNetCoreInstaller@1
  displayName: 'Use .NET Core sdk 2.2.103'
  inputs:
    version: 2.2.103

- task: DotNetCoreCLI@2
  displayName: 'Restore NuGet packages for $(solution)'
  inputs:
    command: 'restore'
    projects: '$(solution)'

- task: DotNetCoreCLI@2
  displayName: 'Build $(solution)'
  inputs:
    command: 'build'
    projects: '$(solution)'
    arguments: '-c $(buildConfiguration)'

- task: DotNetCoreCLI@2
  continueOnError: true
  inputs:
    command: custom
    custom: tool
    arguments: install -g coverlet.console
  displayName: Install Coverlet tool. This task will continue on error.

- task: DotNetCoreCLI@2
  displayName: 'Run tests for $(solution) collecting code coverage result'
  inputs:
    command: test
    projects: 'src/MySolution.SomeProject.Tests/*.csproj'
    arguments: -c $(buildConfiguration) --collect:"XPlat Code Coverage"

- script: coverlet src/MySolution.SomeProject.Tests/bin/$(buildConfiguration)/netcoreapp2.1/MySolution.SomeProject.Tests.dll --target "dotnet" --targetargs "test src/MySolution.SomeProject.Tests --no-build"
  displayName: Run Coverlet to get code coverage.

- task: DotNetCoreCLI@2
  continueOnError: true
  inputs:
    command: custom
    custom: tool
    arguments: install -g dotnet-reportgenerator-globaltool
  displayName: Install ReportGenerator tool

# This outputs Analyzing 0 classes, and an index.htm file is created, but not sure how to access it
- script: reportgenerator -reports:$(Build.SourcesDirectory)/coverage.json -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:HtmlInline_AzurePipelines
  displayName: 'Create reports.'

# Not sure what this should be
- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage'
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: $(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-12-23 08:58:18

所以我让它起作用了。我错过了一些东西,您可以指定coverlet使用的格式。默认情况下,它输出coverage.json,但将格式作为cobertura输出coverage.cobertura.xml。所以这个yaml脚本起作用了:

代码语言:javascript
复制
pool:
  vmImage: macOS-latest

variables:
  solution: 'src/MySolution.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'

steps:
- task: DotNetCoreInstaller@1
  displayName: 'Use .NET Core sdk 2.2.103'
  inputs:
    version: 2.2.103

- task: DotNetCoreCLI@2
  displayName: 'Restore NuGet packages for $(solution)'
  inputs:
    command: 'restore'
    projects: '$(solution)'

- task: DotNetCoreCLI@2
  displayName: 'Build $(solution)'
  inputs:
    command: 'build'
    projects: '$(solution)'
    arguments: '-c $(buildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: 'Run tests for $(solution) collecting code coverage result'
  inputs:
    command: test
    projects: 'src/MySolution.SomeProject.Tests/*.csproj'
    arguments: -c $(buildConfiguration)

- task: DotNetCoreCLI@2
  continueOnError: true
  inputs:
    command: custom
    custom: tool
    arguments: install -g coverlet.console
  displayName: Install Coverlet tool. This task will continue on error.

- script: coverlet src/MySolution.SomeProject.Tests/bin/$(buildConfiguration)/netcoreapp2.1/MySolution.SomeProject.Tests.dll --target "dotnet" --targetargs "test src/MySolution.SomeProject.Tests --no-build" --format cobertura
  displayName: Run Coverlet to get code coverage.

- task: DotNetCoreCLI@2
  continueOnError: true
  inputs:
    command: custom
    custom: tool
    arguments: install -g dotnet-reportgenerator-globaltool
  displayName: Install ReportGenerator tool

- script: reportgenerator -reports:$(Build.SourcesDirectory)/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:HtmlInline_AzurePipelines
  displayName: 'Create reports.'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage'
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: $(Build.SourcesDirectory)/coverage.cobertura.xml
票数 0
EN

Stack Overflow用户

发布于 2019-12-23 08:57:41

应该将以下NuGet PackageReference添加到项目.csproj文件中

代码语言:javascript
复制
<PackageReference Include="coverlet.collector" Version="1.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

您可以按照此链接设置管道

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59434927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档