|
7 | 7 | </PropertyGroup>
|
8 | 8 |
|
9 | 9 | <ItemGroup>
|
10 |
| - <PackageReference Include="coverlet.msbuild" Version="3.2.0" PrivateAssets="all" /> |
| 10 | + <PackageReference Include="coverlet.collector" Version="3.2.0" PrivateAssets="all" /> |
11 | 11 | <PackageReference Include="FluentAssertions" Version="6.10.0" />
|
12 | 12 | <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
13 | 13 | <PackageReference Include="PublicApiGenerator" Version="11.0.0" />
|
|
24 | 24 | <PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" PrivateAssets="all" />
|
25 | 25 | </ItemGroup>
|
26 | 26 |
|
| 27 | + <ItemGroup> |
| 28 | + <VSTestLogger Include="GitHubActions" Visible="false" Condition="$(ContinuousIntegrationBuild) == 'true'" /> |
| 29 | + <VSTestLogger Include="trx%3BLogFileName=TestResults-$(TargetFramework).trx" Visible="false" Condition="$(ContinuousIntegrationBuild) == 'true'" /> |
| 30 | + <VSTestLogger Include="html%3BLogFileName=TestResults-$(TargetFramework).html" Visible="false" /> |
| 31 | + </ItemGroup> |
| 32 | + |
27 | 33 | <PropertyGroup Label="Coverage">
|
28 |
| - <!-- Automatically collect coverage when running `dotnet test` --> |
29 |
| - <CollectCoverage>true</CollectCoverage> |
30 |
| - <!-- Tweak the default coverlet output directory to be `coverage` in the repository root directory --> |
31 |
| - <CoverletOutput>$([MSBuild]::EnsureTrailingSlash($([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine($(MSBuildProjectDirectory),'..','coverage'))))))</CoverletOutput> |
32 |
| - <!-- The default output format is `json` which is not supported by ReportGenerator --> |
33 |
| - <CoverletOutputFormat>cobertura</CoverletOutputFormat> |
| 34 | + <RootDirectory>$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)))</RootDirectory> |
| 35 | + <CoverageReportDirectory>$([System.IO.Path]::Combine($(RootDirectory),'coverage',$(TargetFramework)))</CoverageReportDirectory> |
| 36 | + <VSTestResultsDirectory Condition="$(ContinuousIntegrationBuild) == 'true'">$(RootDirectory)</VSTestResultsDirectory> |
| 37 | + <VSTestResultsDirectory Condition="$(ContinuousIntegrationBuild) != 'true'">$([System.IO.Path]::Combine($(CoverageReportDirectory),'results'))</VSTestResultsDirectory> |
| 38 | + <VSTestCollect>XPlat Code Coverage</VSTestCollect> |
| 39 | + <VSTestLogger>@(VSTestLogger)</VSTestLogger> |
34 | 40 | </PropertyGroup>
|
35 | 41 |
|
36 |
| - <Target Name="GenerateHtmlCoverageReport" AfterTargets="GenerateCoverageResultAfterTest" Condition="$(ContinuousIntegrationBuild) != 'true'"> |
37 |
| - <PropertyGroup> |
38 |
| - <CoverageReportDirectory>$([MSBuild]::EnsureTrailingSlash('$(CoverletOutput)report'))</CoverageReportDirectory> |
39 |
| - <OpenCommand Condition="$([MSBuild]::IsOSPlatform('Linux'))">xdg-open</OpenCommand> |
40 |
| - <OpenCommand Condition="$([MSBuild]::IsOSPlatform('OSX'))">open</OpenCommand> |
41 |
| - <OpenCommand Condition="$([MSBuild]::IsOSPlatform('Windows'))">explorer</OpenCommand> |
42 |
| - </PropertyGroup> |
| 42 | + <Target Name="GenerateHtmlCoverageReport" AfterTargets="VSTest" Condition="$(TargetFramework) != ''"> |
| 43 | + <ItemGroup> |
| 44 | + <CoverletReport Include="$(VSTestResultsDirectory)/*/coverage.cobertura.xml" /> |
| 45 | + </ItemGroup> |
43 | 46 | <ReportGenerator ReportFiles="@(CoverletReport)" TargetDirectory="$(CoverageReportDirectory)" />
|
44 |
| - <!-- executing "explorer path\to\index.html" returns exit code 1, so we ignore it --> |
45 |
| - <Exec WorkingDirectory="$(CoverageReportDirectory)" Command="$(OpenCommand) index.html" Condition="$(OpenCommand) != ''" IgnoreExitCode="true" /> |
46 | 47 | </Target>
|
47 | 48 |
|
48 |
| - <Target Name="WriteCoverageReportPathForGitHubActions" AfterTargets="GenerateCoverageResultAfterTest" Condition="$(GITHUB_OUTPUT) != ''"> |
| 49 | + <!-- Because of https://github.com/microsoft/vstest/issues/2378 --> |
| 50 | + <Target Name="MoveCoverletReport" AfterTargets="GenerateHtmlCoverageReport"> |
| 51 | + <Move SourceFiles="@(CoverletReport)" DestinationFolder="$(CoverageReportDirectory)" /> |
49 | 52 | <PropertyGroup>
|
50 |
| - <CoverageReports>@(CoverletReport, ',')</CoverageReports> |
| 53 | + <CoverletReport>@(CoverletReport)</CoverletReport> |
51 | 54 | </PropertyGroup>
|
52 | 55 | <ItemGroup>
|
53 |
| - <GitHubOutput Include="coverage-reports=$(CoverageReports)" /> |
| 56 | + <CoverletReportParentDirectory Include="$([System.IO.Path]::Combine($(CoverletReport),'..'))" /> |
54 | 57 | </ItemGroup>
|
55 |
| - <WriteLinesToFile File="$(GITHUB_OUTPUT)" Lines="@(GitHubOutput)" /> |
| 58 | + <RemoveDir Directories="@(CoverletReportParentDirectory)" /> |
| 59 | + </Target> |
| 60 | + |
| 61 | + <Target Name="OpenHtmlCoverageReport" AfterTargets="MoveCoverletReport" Condition="$(ContinuousIntegrationBuild) != 'true'"> |
| 62 | + <PropertyGroup> |
| 63 | + <OpenCommand Condition="$([MSBuild]::IsOSPlatform('Linux'))">xdg-open</OpenCommand> |
| 64 | + <OpenCommand Condition="$([MSBuild]::IsOSPlatform('OSX'))">open</OpenCommand> |
| 65 | + <OpenCommand Condition="$([MSBuild]::IsOSPlatform('Windows'))">explorer</OpenCommand> |
| 66 | + </PropertyGroup> |
| 67 | + <!-- executing "explorer path\to\index.html" returns exit code 1, so we ignore it --> |
| 68 | + <Exec WorkingDirectory="$(CoverageReportDirectory)" Command="$(OpenCommand) index.html" Condition="$(OpenCommand) != ''" IgnoreExitCode="true" /> |
56 | 69 | </Target>
|
57 | 70 |
|
58 | 71 | <ItemGroup>
|
|
0 commit comments