coverlet
coverlet copied to clipboard
AssemblyResolutionException for Microsoft.AspNetCore.Http.Features which exists in refs folder
Problem:
Code coverage not showing up for primary project dll.
Analysis:
Project file is a .NET Core 6 MVC Webapp. We have a dependency on the Microsoft.AspNetCore.App framework.
Error is the following:
TpTrace Warning: 0 : 10244, 1, 2022/05/02, 13:29:05.588, 139093313616, datacollector.dll, [coverlet]Unable to instrument module: C:\dev\ocp\identity-provider\IdentityProvider.UnitTests\bin\Release\net6.0\IdentityProvider.dll because : AssemblyResolutionException for 'Microsoft.AspNetCore.Http.Features, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Try to add <PreserveCompilationContext>true</PreserveCompilationContext> to test projects </PropertyGroup> or pass '/p:CopyLocalLockFileAssemblies=true' option to the 'dotnet test' command-line
I've added the <PreserveCompilationContext>true</PreservceCompilationContext>
to our test project. This forces the framework dll's to exist in bin\Release\net6.0\refs, but the error persists, as Microsoft.AspNetCore.Http.Features now only lives in that refs folder instead of one folder above.
This issue is likely caused by a breaking change to this assembly: https://docs.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/6.0/microsoft-aspnetcore-http-features-package-split
Workaround:
This issue can be resolved by moving the Microsoft.AspNetCore.Http.Features.dll file from the refs folder into the net6.0 folder one level above it.
This workaround is much more difficult in our CI pipeline.
Extra notes:
Here's the command we're running: dotnet test -p:Version=1.0.0 -p:CopyLocalLockFileAssemblies=true --no-restore --configuration release --settings ./pipeline-tests.runsettings --verbosity n --diag:log.txt --logger:"trx;logfilename=out.trx" --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
I've attached the diagnostic log files, from before moving the assembly and after.
Thanks for reporting this.
Has anyone had a chance to look at this? I am running into this as well, and the workaround does present an odd issue for CI builds.
I'm also encountering this issue. I can confirm that setting PreserveCompilationContext on the test project and then manually copying the Microsoft.AspNetCore.Mvc.ViewFeatures.dll out of the refs folder into the net6.0 works. Anyone come up with any other solutions?
Until there's a fix for this issue here is what I'm adding to my test project (csproj) to resolve. Alternatively you could use <Exec Command="xcopy ..>
instead of <Copy>
<PropertyGroup Condition=" '$(CollectCoverage)' == 'true' ">
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<!--...-->
<Target Name="FixCodeCoverage" AfterTargets="Build" Condition=" '$(CollectCoverage)' == 'true' ">
<Warning Text="Fixing Coverlet Microsoft.AspNetCore.Mvc.ViewFeatures.dll issue: https://github.com/coverlet-coverage/coverlet/issues/1328"></Warning>
<Copy
SourceFiles="$(ProjectDir)$(OutputPath)refs\Microsoft.AspNetCore.Mvc.ViewFeatures.dll"
DestinationFolder="$(ProjectDir)$(OutputPath)"
/>
</Target>
See this issue. Seems related
This issue is stale because it has been open for 3 months with no activity.