I'm currently trying to create a Coverlet coverage report with a pipeline on Azure DevOps. But, since my project is a ".Net FrameWork 4.7" project, I can't create a coverage report using "DotNetCoreCLI@2" task like a ".Net Core" project.
There's my pipeline code:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
buildPlatform: 'Any CPU'
buildConfiguration: 'release'
Tests.Filter: '**\UnitTestProject1.dll'
Tests.Filter.Criteria: 'TestCategory!=Medium&TestCategory!=Large'
Tests.Filter.SettingsFile:
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '**/*.sln'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: 'test'
projects: |
$(Tests.Filter)
!**\obj\**
publishTestResults: true
arguments: -c $(BuildConfiguration) --collect:"XPlat Code Coverage"
- task: DotNetCoreCLI@2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool
- script: reportgenerator -reports:$(Agent.TempDirectory)/**/*.coverage -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"Cobertura"
displayName: Create reports
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)\TestResults\Coverage\*.xml'
When all test are successful I receive:
Starting: Create reports
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.164.2
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
reportgenerator -reports:D:\a\_temp/**/*.coverage -targetdir:D:\a\1\s/coverlet/reports -reporttypes:"Cobertura"
========================== Starting Command Output ===========================
"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\e4754795-32ae-47f2-bd62-d1c8b925eb84.cmd""
2020-09-28T14:56:09: Arguments
2020-09-28T14:56:09: -reports:D:\a\_temp/**/*.coverage
2020-09-28T14:56:09: -targetdir:D:\a\1\s/coverlet/reports
2020-09-28T14:56:09: -reporttypes:Cobertura
2020-09-28T14:56:09: The report file pattern 'D:\a\_temp/**/*.coverage' is invalid. No matching files found.
2020-09-28T14:56:09: No report files specified.
##[error]Cmd.exe exited with code '1'.
Finishing: Create reports
I also tried to use VSTest@2 and activate "CodeCoverageEnable" but the code coverage is not compatible with Azure DevOps and a download is necessary to see the coverage report.
There's my pipeline code for VSTest@2:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
buildPlatform: 'Any CPU'
buildConfiguration: 'release'
Tests.Filter: '**\UnitTestProject1.dll'
Tests.Filter.Criteria: 'TestCategory!=Medium&TestCategory!=Large'
Tests.Filter.SettingsFile:
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '**/*.sln'
- task: VSTest@2
displayName: 'Running UnitTests'
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
$(Tests.Filter)
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
testFiltercriteria: '$(Tests.Filter.Criteria)'
runSettingsFile: '$(Tests.Filter.SettingsFile)'
runInParallel: true
testRunTitle: 'Running UnitTests for $(Tests.Filter)'
platform: '$(buildPlateform)'
configuration: -c '$(buildConfiguration)'
codeCoverageEnabled: true
Is there a way to create a coverage report compatible with Azure DevOps (Cobertura or JaCoCo) for my ".Net FrameWork 4.7" project without changing the project .Net FrameWork Version nor the type of the project?