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

MS CodeCoverage + SourceLink + ReportGenerator = No Code Coverage Report #141

Open
rainman-63 opened this issue Oct 15, 2024 · 4 comments
Open

Comments

@rainman-63
Copy link

When using MS CodeCoverage with SourceLink (Microsoft.SourceLink.GitHub in this case), and setting the ContinuousIntegrationBuild element in the csproj to true, the output reports will have the file path removed from the filename attributes.

Using SourceLink will cause the PDB to be altered, adding the CustomDebugAttribute and removing part of the file paths to be replaced with /_, which will result in the following code coverage report:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<coverage line-rate="0.5" branch-rate="1" complexity="2" version="1.9" timestamp="1728997951" lines-covered="1" lines-valid="2">
  <packages>
    <package line-rate="0.5" branch-rate="1" complexity="2" name="NoCodeCoverage">
      <classes>
        <class line-rate="0.5" branch-rate="1" complexity="2" name="NoCodeCoverage.MyMath" filename="/_/src/NoCodeCoverage/MyMath.cs">
          <methods>
            <method line-rate="1" branch-rate="1" complexity="1" name="Add" signature="(int, int)">
              <lines>
                <line number="15" hits="1" branch="False" />
              </lines>
            </method>
            <method line-rate="0" branch-rate="1" complexity="1" name="Subtract" signature="(int, int)">
              <lines>
                <line number="24" hits="0" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="15" hits="1" branch="False" />
            <line number="24" hits="0" branch="False" />
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>

Tooling like ReportGenerator use the filename to access the file to build the code coverage report, but no such file path exists on the local machine for /_/src/NoCodeCoverage/MyMath.cs.

Other tooling like coverlet do not seem to have the same issue when using SourceLink.

I've attached a sample application that will exhibit the issue, it just needs to be setup with a git repo. NoCodeCoverage.zip

Thanks,

Raymond

@jakubch1
Copy link
Member

@rainman-63 thanks for reporting this. ReportGenerator works good with /_/ we are using it in our pipelines. You can maybe try to upgrade ReportGenerator in your pipeline and/or provide argument -sourcedirs.

You can also try to use: <Configuration><DeterministicReport>False</DeterministicReport></Configuration> in your configuration to try to resolve those paths. I think you need to upgrade Microsoft.CodeCoverage package to latest in your project to take effect.

@fhnaseer could you please add DeterministicReport option to our public documentation?

@jbe2277
Copy link

jbe2277 commented Nov 6, 2024

I see the same issue with my bat file here: https://github.com/jbe2277/waf/blob/34629b5f4a9d83d320050fa0b8b4da0528b07fd5/build/BuildRelease.bat

Output of reportgenerator:

reportgenerator -reports:../out/CodeCoverageReport/System.Waf.cobertura.xml -targetdir:../out/CodeCoverageReport -reporttypes:"MarkdownSummaryGithub"
2024-11-06T21:42:42: Arguments
2024-11-06T21:42:42:  -reports:../out/CodeCoverageReport/System.Waf.cobertura.xml
2024-11-06T21:42:42:  -targetdir:../out/CodeCoverageReport
2024-11-06T21:42:42:  -reporttypes:MarkdownSummaryGithub
2024-11-06T21:42:42: File '/_/src/System.Waf/Samples/BookLibrary/BookLibrary.Library.Presentation/App.xaml.cs' does not exist (any more).
2024-11-06T21:42:42: File '/_/src/System.Waf/Samples/BookLibrary/BookLibrary.Library.Presentation/Converters/LanguageToStringConverter.cs' does not exist (any more).
2024-11-06T21:42:42: File '/_/src/System.Waf/Samples/BookLibrary/BookLibrary.Library.Presentation/Converters/StringToUriConverter.cs' does not exist (any more).
...

I'm using the latest version of dotnet-coverage and reportgenerator.

@Cjewett
Copy link

Cjewett commented Nov 26, 2024

Is there any documentation or guidance outlining when paths are normalized or not? We're seeing an issue where we enabled ContinuousIntegrationBuild=true and the following happened:

Repository 1:
Linux - normalized paths "/_/"
Windows - absolute path

Repository 2:
Linux - absolute path
Windows - absolute path

We didn't go out of our way to enable source linking at all, so we're a bit confused on what could have happened and trying to track down the discrepancies.

Edit: It looks like upgrading from an older Microsoft.CodeCoverage version to the latest (17.12.0) fixed the case where Repository 1 had normalized paths on Linux.

@fhnaseer
Copy link
Member

@Cjewett I have added documentation for DeterministicReport https://github.com/microsoft/codecoverage/blob/main/docs/configuration.md

@jbe2277 I see that you are using 17.11.1 version of sdk https://github.com/jbe2277/waf/blob/34629b5f4a9d83d320050fa0b8b4da0528b07fd5/src/Samples.UITest/Directory.Packages.props#L9. Can you please use 17.12.0 and try again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants