Skip to content

Sonarqube format clashes with DeterministicSourcePaths=true #668

Closed

Description

@JustusGreiberORGADATA

Hi,

when you have a test coverage report with DeterministicSourcePaths=true, paths will start with /_/ to indicate the source root of the compilation. When you convert a report like this to the Sonarqube format, it will use the same paths. These paths sadly don't satisfy the requirements of the format, which include the following for the path:

Its path attribute can be either absolute or relative to the project's base directory (root module).

https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/test-coverage/generic-test-data/

Now I am not sure if this tool should be responsible for modifying the paths. I could totally understand if this is out of scope. On the other hand I could also understand if handling paths like this is out of scope for the "Sonarqube Generic test coverage report format" itself, considering that it's supposed to be generic. So I wanted to open this issue as a discussion about whether normalizing the paths for the coverage format is something this tool should do or not.

Activity

  1. JustusGreiberORGADATA commented on May 13, 2024

    @JustusGreiberORGADATA
    Author

    I just realized that GitHub also has the discussion feature and it is enabled on this repository. If this better fits there, maybe someone could move this issue, to a discussion.

  2. danielpalme commented on May 13, 2024

    @danielpalme
    Owner

    In your case you can use a little Powershell script to set the correct the path information. This might look like the following example:

    (gc "coverage.xml") | % { $_ -replace "/_/", "/real/path/" } | Out-File "coverage.xml" -Encoding UTF8

    ReportGenerator can't guess the correct path in that case.

  3. JustusGreiberORGADATA commented on May 14, 2024

    @JustusGreiberORGADATA
    Author

    ReportGenerator can't guess the correct path in that case.

    Interesting, I thought ReportGenerator in some cases already does try to determine the right paths here:

    https://github.com/danielpalme/ReportGenerator/blob/main/src/ReportGenerator.Core/Parser/FileReading/LocalFileReader.cs#L106-L168

    That's why I thought maybe it could, for example, emit absolute paths and be spec-compliant that way. As I said, though, I am totally fine with this being out of scope.

  4. danielpalme commented on May 14, 2024

    @danielpalme
    Owner

    Interesting, I thought ReportGenerator in some cases already does try to determine the right paths here:

    https://github.com/danielpalme/ReportGenerator/blob/main/src/ReportGenerator.Core/Parser/FileReading/LocalFileReader.cs#L106-L168

    Correct. But this only works (automatically) if you are using Azure DevOps or Github Actions.

    Another option would be to supply a directory manually via the -sourcedirs:.... command line parameter.
    Maybe that worth a try for you.

  5. JustusGreiberORGADATA commented on May 14, 2024

    @JustusGreiberORGADATA
    Author

    Another option would be to supply a directory manually via the -sourcedirs:.... command line parameter. Maybe that worth a try for you.

    Thanks, unfortunately I already tried providing the command line parameter before writing this issue and noticed that it does not cause ReportGenerator to actually change the paths, when converting a report to the Sonarqube format. As far as I understand, it is only used to load the files for some other tasks.

    I just thought this tool supporting something like -sourcedirs:... -convertPathsToAbsolute for converting a report might be something that's worth implementing, considering the SonarQube format does not support the deterministic path style.

    (And then maybe defaulting to true for that option if the format is SonarQube, since it seems like a sane default.)

    Anyway, I will try the manual replacement; that should work too. Thanks for the suggestion.

  6. Sam13 commented on Oct 30, 2026

    @Sam13

    Same problem here:
    Providing source dirs allows ReportGenerator to find the sources and display it but does not change the path's e.g. in Sonar XML file.
    @danielpalme Out of the box support for that would be nice

  7. added 2 commits that reference this issue on Nov 8, 2026
  8. danielpalme commented on Nov 8, 2026

    @danielpalme
    Owner

    In 1eb5e17 I made a change to the SonarQube export.
    SonarQube report now exports mapped/absolute paths if they got modified by the given source directories

    fileElement = new XElement("file", new XAttribute("path", fileAnalysis.MappedPath));

    I will include this feature in the next release. I will publish it once .NET 11 is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions