coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.94k stars 386 forks source link

Not given a value for the Required parameter "InstrumenterState" #1357

Closed duyn9uyen closed 2 years ago

duyn9uyen commented 2 years ago

I am having trouble with generating a coverage report using Azure Devops Pipelines. The agent pool uses this docker linux image. Here is my task

ADO Task:
- task: DotNetCoreCLI@2
      inputs:
        command: 'test'
        projects: '**/*.Tests.csproj'
        arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura'
      displayName: 'dotnet test $(buildConfiguration)'

error MSB4044: The "Coverlet.MSbuild.Tasks.CoverageResultTask" task was not given a value for the required parameter "InstrumenterState". ... ##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1

When I run the cli command locally (Windows 10), it works fine and no error is mentioned about InstrumenterState.

dotnet test */.Tests.csproj -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura

duyn9uyen commented 2 years ago

I solved my issue. In my test project .csproj file, I had a reference to both coverlet.collector AND coverlet.msbuild. I had to only include coverlet.msbuild.

<PackageReference Include="coverlet.msbuild" Version="3.1.2">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>