Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Coverlet.MSbuild.Tasks.CoverageResultTask" task was not given a value for the required parameter "InstrumenterState" #480

Closed
farhad-taran-cko opened this issue Jun 29, 2019 · 13 comments
Labels
needs more info More details are needed

Comments

@farhad-taran-cko
Copy link

Hello,

I have setup a post build event in my shared test library, this library has not tests but is referenced by all my test projects, I did this because I want to automatically generate the reports every-time the projects are built.

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="cd $(SolutionDir)&#xD;&#xA;dotnet test" />
  </Target>

however I am getting the following error when I try to build the solution and the build hangs:

C:\...\packages\coverlet.msbuild\2.6.2\build\coverlet.msbuild.targets(41,5): error MSB4044: The "Coverlet.MSbuild.Tasks.CoverageResultTask" task was not given a value for the required parameter "InstrumenterState".

Directory.Build.Props
`

<PropertyGroup>
    <IsTestProject>false</IsTestProject>
    <IsTestProject Condition="$(MSBuildProjectName.EndsWith('Tests')) OR $(MSBuildProjectName.EndsWith('Test'))">true</IsTestProject>
    <CollectCoverage Condition="!$(IsTestProject)">false</CollectCoverage>
    <CollectCoverage Condition="$(IsTestProject) AND $(CollectCoverage) == ''">true</CollectCoverage>
</PropertyGroup>

<PropertyGroup Label="CollectCodeCoverageResults" Condition="$(IsTestProject) AND $(CollectCoverage)">
    <CoverletOutputFormat>opencover</CoverletOutputFormat>
<_SlnDir>..\..\</_SlnDir>
    <_BaseDir>..\..\coverage-results\</_BaseDir>
    <CoverletBaseDir>$(_BaseDir)Coverage\</CoverletBaseDir>
    <CoverletResultsDir>$(_BaseDir)Results\</CoverletResultsDir>
    <CoverletBaseDir Condition="$([MSBuild]::IsOSUnixLike())">$(CoverletBaseDir.Replace('\', '/'))</CoverletBaseDir>
<SolutionDir Condition="$([MSBuild]::IsOSUnixLike())">$(_SlnDir.Replace('\', '/'))</SolutionDir>
    <CoverletResultsDir Condition="$([MSBuild]::IsOSUnixLike())">$(CoverletResultsDir.Replace('\', '/'))</CoverletResultsDir>
    <CoverletOutput>$(CoverletBaseDir)$(MSBuildProjectName).xml</CoverletOutput>
    <Exclude>[xunit*]*,[*Tests]*,[*Test]*</Exclude>
</PropertyGroup>

`

Directory.Build.Targets
`

<ItemGroup>
    <DotNetCliToolReference Include="dotnet-reportgenerator-cli" Version="4.1.10" />
    <PackageReference Include="coverlet.msbuild" Version="2.6.2">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
    <PackageReference Include="xunit.runner.reporters" Version="2.4.1" />
    <PackageReference Include="xunit.runner.utility" Version="2.4.1" />
    <PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.13" />
</ItemGroup>

<Target Name="CovertReportResults" AfterTargets="GenerateCoverageResult" Condition="$(CollectCoverage)">
    <!-- Merges the reports into one for both cobertura and sonarqube formats -->
    <Exec Command="dotnet reportgenerator -reports:$(CoverletBaseDir)*.xml -targetdir:$(CoverletResultsDir) -reporttypes:Cobertura;SonarQube -verbosity:Verbose" WorkingDirectory="$(ProjectDir)" />
    <!-- Gives the summary in an Azure Pipelines look & feel -->
    <Exec Command="dotnet reportgenerator -reports:$(CoverletResultsDir)Cobertura.xml -targetdir:$(CoverletResultsDir) -reporttypes:HtmlInline_AzurePipelines;Cobertura -verbosity:Verbose" WorkingDirectory="$(ProjectDir)" />

<Exec Command="dotnet reportgenerator -reports:$(CoverletResultsDir)Cobertura.xml -targetdir:$(SolutionDir) -reporttypes:TextSummary -verbosity:Verbose" WorkingDirectory="$(ProjectDir)" />
</Target>

`

@yhvicey
Copy link

yhvicey commented Jun 30, 2019

I worked around this by combining Traversal SDK and conditional switch. You can use dirs.proj file to put all your needed project on a build tree and let the sdk handle the traversal. Then, with your conditional switch property, I guess you can workaround this problem. My conditional switch looks like below:

<!-- Coverlet settings -->
<PropertyGroup>
    <!-- Enable coverlet by default -->
    <EnableCoverlet Condition=" $(EnableCoverlet) == '' AND ($(MSBuildProjectName.ToLower().EndsWith('test')) OR $(MSBuildProjectName.ToLower().EndsWith('tests'))) ">true</EnableCoverlet>
</PropertyGroup>

<ItemGroup Condition=" $(EnableCoverlet) == 'true' ">
    <PackageReference Include="coverlet.msbuild" Version="2.6.2" />
</ItemGroup>

@farhad-taran-cko
Copy link
Author

@yhvicey thanks for your response, any chance you could send me an example including the traversal snippet?

@yhvicey
Copy link

yhvicey commented Jun 30, 2019

Imaging we have a project folder like below:

(root)
|- src
|    |- Project
|         |- Project.csproj
|    |- dirs.proj // Ignore this, use it if you like
|- test
|    |- TestProject
|    |    |- TestProject.csproj
|    |- dirs.proj // Let's call it second dirs.proj
|- dirs.proj // Let's call it first dirs.proj

Your first dirs.proj will look like below:

<Project Sdk="Microsoft.Build.Traversal">
    <ItemGroup>
        <ProjectReference Include="src\dirs.proj" />
        <ProjectReference Include="test\dirs.proj" />
    </ItemGroup>
</Project>

Your second dirs.proj will look like below:

<Project Sdk="Microsoft.Build.Traversal">
    <ItemGroup>
        <ProjectReference Include="TestProject/TestProject.csproj" />
        <!-- Other projects -->
    </ItemGroup>
</Project>

Note: Use global.json to specify versions for those SDKs globally, otherwise you will have to specify them like <Project Sdk="Microsoft.Build.Traversal/x.x.x"> in every traversal project. Below is a sample of global.json:

{
  "msbuild-sdks": {
    "Microsoft.Build.NoTargets": "1.0.73",
    "Microsoft.Build.Traversal": "2.0.12"
  }
}

And you can use this pattern recursively. I guess the root cause here is this coverlet version (2.6.2 in my case) cannot handle non-test project properly, so we have to avoid making coverlet available for those non-test projects, like your root project. By using traversal, you can make IsTestProject untouched in those dirs.proj and achieve your goal (Build one root dirs.proj to generate overall report).

Besides, I doubt this might be caused by your property. IsTestProject is an common property which helps SDKs decide if it's a test project, so I think this might be worked around by using other property instead, like EnableCoverlet.

@MarcoRossignoli
Copy link
Collaborator

thank's @yhvicey for help!
@farhad-taran-cko let know us if it works!

@MarcoRossignoli MarcoRossignoli added the needs more info More details are needed label Jul 1, 2019
@fkucuk
Copy link

fkucuk commented Jul 29, 2019

for the record, I've faced the same error, and I've realized that I've had added coverlet nuget to business projects. When I removed it, it's been fixed.

@maxoizs
Copy link

maxoizs commented Aug 19, 2019

in my case after getting that error, I've installed MS.Net.Test.Sdk which cleared the error so in my test project package I do have
coverlet.msbuild version="2.6.3"
Microsoft.NET.Test.Sdk version="16.2.0"
Microsoft.CodeCoverage version="16.2.0" --- which a dependency of Sdk

<

@MarcoRossignoli
Copy link
Collaborator

@farhad-taran-cko any news?

@MarcoRossignoli
Copy link
Collaborator

Close for stale discussion.
Feel free to re-open if needed.

@soroshsabz
Copy link

soroshsabz commented Jan 23, 2020

I have an open source project in GitHub, and we have problem to reporting testing result from issue Romanx/Cake.Coverlet#30 , we install Coverlet.MSBuild to Test project, but we got this error in appveyor .

Did you can any help, please reopen this issue @MarcoRossignoli

@MarcoRossignoli
Copy link
Collaborator

@soroshsabz seem not related to coverlet I did some test with your project you need to update some ref to run nunit test with dotnet test

https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-nunit#creating-the-test-project

image

run

dotnet test /p:CollectCoverage=true

image

@soroshsabz
Copy link

Thanks you very much :) @MarcoRossignoli

@MarcoRossignoli
Copy link
Collaborator

You're welcome!

@MarcoRossignoli
Copy link
Collaborator

Ah @soroshsabz if you can use vstest integration that is better than msbuild https://github.com/tonerdo/coverlet#vstest-integration-preferred-due-to-know-issue if you're in trouble let me know.

0xced added a commit to 0xced/xunit-logging that referenced this issue Apr 28, 2021
Adding a package reference in a non-test project would lead to this error when running `dotnet test` in the repository root:
> ~/.nuget/packages/coverlet.msbuild/3.0.3/build/coverlet.msbuild.targets(70,5): error MSB4044: The "Coverlet.MSbuild.Tasks.CoverageResultTask" task was not given a value for the required parameter "InstrumenterState".

See coverlet-coverage/coverlet#480 (comment)

Also delete the workaround for the bug in generation of _LocalTopLevelSourceRoot which is [no longer necessary](coverlet-coverage/coverlet#863).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More details are needed
Projects
None yet
Development

No branches or pull requests

6 participants