Skip to content

Instantly share code, notes, and snippets.

@karenpayneoregon
Last active February 7, 2024 19:33
Show Gist options
  • Save karenpayneoregon/89ac896a1a935f4e706b937e710ccc96 to your computer and use it in GitHub Desktop.
Save karenpayneoregon/89ac896a1a935f4e706b937e710ccc96 to your computer and use it in GitHub Desktop.
reduced source path
<PropertyGroup>
<PathMap>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=./</PathMap>
</PropertyGroup>
@disouzam
Copy link

Hello, @karenpayneoregon :

I have seen this tip on Twitter when you posted about it recently and today I decided to test it.

But adding this configuration broke my test coverage instrumentation. Have you heard anything about this and know any workaround? I liked the idea of reduced source path but I was surprised by this side effect.

Thanks for sharing your knowledge! ;)

@disouzam
Copy link

So far, I found this alternative:

https://stackoverflow.com/a/74860488

image

@karenpayneoregon
Copy link
Author

When you say test coverage instrumentation can provide more details?

@disouzam
Copy link

Sure!

When running tests, I use xUnit and coverlet.msbuild / coverlet.collector to calculate the code coverage and later I use ReportGenerator tool to generate a nice HTML report.

After I adopted in my projects - to test your idea that I found very useful - the PathMap configuration, calculation of code coverage presented a bug.

This is the bug during code coverage calculation - I assume changing paths also affected the way coverlet.msbuild interacted with build artifacts.
image

This is the normal code coverage calculation.

image

And I run tests through tasks in VS Code, chained with other tasks to generate code coverage report, but the command in the end is (full project path were ommited since it is a closed source project):

dotnet.exe test Tests\Tests.csproj -v:Minimal -c:Debug -p:CollectCoverage=true -p:CoverletOutputFormat=opencover -p:CoverletOutput=Tests\coverage.opencover.xml -p:ThresholdType=Branch -p:Threshold=70 --no-build

@disouzam
Copy link

When I made the changes I mentioned previously, I got the benefit of reduced short path with the additional benefit of having correct code coverage calculation using coverlet.

@disouzam
Copy link

@karenpayneoregon : if you need further info, please let me know. The project in question is closed source but I can try to spin up a minimal one in my GitHub repo if necessary.

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