coverlet-coverage / coverlet

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

coverlet.msbuild doesn't work with PathMap property #1349

Closed carlreinke closed 2 weeks ago

carlreinke commented 2 years ago

The PathMap property seems to not be reflected in the CoverletSourceRootsMapping file.

I ended up adding an extra target to my project to make it work:

  <Target Name="_PathMaps" BeforeTargets="ReferencedPathMaps">
    <ItemGroup Condition="'$(PathMap)' != ''">
      <_escapedPathMap Include="$([System.Text.RegularExpressions.Regex]::Split(`$(PathMap)`, `(?&lt;=(?:^|[^,])(?:,,)*),(?!,)`))" />
      <_pathMap Include="@(_escapedPathMap->'%(Identity)'->Replace(',,', ','))" />
      <_projectWithPathMaps Include="@(AnnotatedProjects->'%(FullPath)')" PathMap="%(_pathMap.Identity)" />
      <_mapping Include="@(_projectWithPathMaps->'%(Identity)|%(PathMap)')" />
    </ItemGroup>
  </Target>

I'm not an MSBuild expert, so maybe there's a better way to do it.

MarcoRossignoli commented 2 years ago

We rely on MSBuild target for deterministic path https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.msbuild.tasks/coverlet.msbuild.targets#L11 we're not in control of it. Maybe you can ask on the SDK side https://github.com/dotnet/sdk