Switch to use relative paths in OpenCover report
See original GitHub issueI am running coverlet in a self-hosted GitLab instance to collect code coverage for Sonarqube. Problem is, we have Windows runners and the test job and the sonar job can run in different absolute paths. This causes Sonarqube to be unable to calculate code coverage because the absolute paths from the first job point nowhere.
This is the command I am using:
coverlet $TEST_PROJECT\bin\Debug\$TEST_PROJECT.dll \
--output "./TestResults/" \
--target nunit3-console \
--targetargs "$TEST_PROJECT\bin\Debug\$TEST_PROJECT.dll --result ./TestResults/TestResult.xml" \
--format opencover
This is what the report looks like (with anonymized paths):
<File uid="1" fullPath="C:\Gitlab-Runner-02\builds\Fu_ads7S\0\APP_PROJECT\File1.cs"/>
<File uid="2" fullPath="C:\Gitlab-Runner-02\builds\Fu_ads7S\0\APP_PROJECT\File2.cs"/>
<File uid="3" fullPath="C:\Gitlab-Runner-02\builds\Fu_ads7S\0\APP_PROJECT\File2.cs"/>
How can I make coverlet generate the opencover with paths relative to execution/project instead of absolute ones?
I looked at multiple issues similar to this one but didn’t see any resolution on what to do.
I also read the docs, but the only options I saw  --use-source-link or somehow using deterministic builds.
With source link enabled it still generated absolute paths and I haven’t tried deterministic build because it didn’t seem straightforward.
Issue Analytics
- State:
 - Created 2 years ago
 - Comments:12 (1 by maintainers)
 

Top Related StackOverflow Question
Thanks @Evangelink @RedlineTriad , I’ve mentioned this to our PM (about adding support for the cobertura format for the Sonar C# offering).
Same problem here. My workaround (for linux): Runner1:
Runner2:
Explanation: $PWD - variable with current path sed -i “s|$PWD|CURRENTDIRECTORYREPLACEMENT|g” opencover.xml - replace all occurrences of current path with string “CURRENTDIRECTORYREPLACEMENT” sed -i “s|CURRENTDIRECTORYREPLACEMENT|$PWD|g” opencover.xml - replace all occurances of string “CURRENTDIRECTORYREPLACEMENT” with current path After that when i run sonar scanner i got opencover.xml with correct paths