Skip to content

Commit

Permalink
Switch to using a before and after target
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKotsenas committed Jun 11, 2024
1 parent e3c606f commit cc2beb3
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions build/targets/tests/Tests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@
<!-- Enable test logging to TRX files and place them in the artifacts directory -->
<VSTestLogger>trx%3bLogFileName=$(MSBuildProjectName).trx</VSTestLogger>
<VSTestResultsDirectory Condition="'$(VSTestResultsDirectory)' == ''">$(ArtifactsTestResultsPath)/$(TargetFramework)</VSTestResultsDirectory>
<_TestCodeCoverageMergedReport>$(ArtifactsTestResultsPath)/report.cobertura.xml</_TestCodeCoverageMergedReport>

<_TestCoverageGlob>$(ArtifactsTestResultsPath)/**/*.cobertura.xml</_TestCoverageGlob>
<_TestCoverageReportDirectory>$(ArtifactsTestResultsPath)/coverage</_TestCoverageReportDirectory>
</PropertyGroup>

<Target Name="GenerageCodeCoverageReport" AfterTargets="Test;VSTest" Condition=" '$(IsTestProject)' == 'true' ">
<Target Name="CleanCoverageReport" BeforeTargets="Test;VSTest" Condition=" '$(IsTestProject)' == 'true' ">
<!-- Prevent this previous runs' coverage files from being merged into this report run. -->
<RemoveDir Directories="$(_TestCoverageReportDirectory)" />

<ItemGroup>
<_CoverageFiles Include="$(_TestCoverageGlob)" />
</ItemGroup>
<Delete Files="@(_CoverageFiles)" />
<ItemGroup>
<_CoverageFiles Remove="@(_CoverageFiles)" />
</ItemGroup>
</Target>

<Target Name="GenerateCoverageReport" AfterTargets="Test;VSTest" Condition=" '$(IsTestProject)' == 'true' ">
<ItemGroup>
<_CoverageFiles Include="$(ArtifactsTestResultsPath)/**/*.cobertura.xml" />
<_CoverageFiles Include="$(_TestCoverageGlob)" />
</ItemGroup>
<ReportGenerator ProjectDirectory="$(MSBuildProjectDirectory)" ReportFiles="@(_CoverageFiles)" TargetDirectory="$(ArtifactsTestResultsPath)/coverage" ReportTypes="MarkdownSummaryGithub;Cobertura;HtmlInline" />
<Delete Files="@(_CoverageFiles)" /><!-- Prevent this run's coverage files from being merged into the next run. -->
<ReportGenerator ProjectDirectory="$(MSBuildProjectDirectory)" ReportFiles="@(_CoverageFiles)" TargetDirectory="$(_TestCoverageReportDirectory)" ReportTypes="MarkdownSummaryGithub;Cobertura;HtmlInline" />
</Target>
</Project>

0 comments on commit cc2beb3

Please sign in to comment.