coverlet: [coverlet] Unable to instrument module - NET 5 - Microsoft.Extensions.Logging.Abstractions
For some test projects, but not all, we get
/home/AzDevOps/.nuget/packages/coverlet.msbuild/3.1.0/build/coverlet.msbuild.targets(39,5): warning : [coverlet] Unable to instrument module: MyApi.dll because : AssemblyResolutionException for ‘Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60’. Try to add <PreserveCompilationContext></PreserveCompilationContext> to test projects </PropertyGroup> or pass '/p:CopyLocalLockFileAssemblies=’ option to the ‘dotnet test’ command-line
Tried:
- Adding
<PreserveCompilationContext>true</PreserveCompilationContext>to csprojs - Also pass
/p:CopyLocalLockFileAssemblies=truetodotnet test - Included a package reference to Microsoft.Extensions.Logging.Abstractions directly in the test projects.
- upgrade coverlet from 3.0.3 to 3.1.0
Related:
- https://github.com/coverlet-coverage/coverlet/issues/1098 (but I can’t use preview packages),
- https://github.com/coverlet-coverage/coverlet/issues/1221 (no solution yet)
- https://github.com/coverlet-coverage/coverlet/issues/1102 (copy to publish not possible for us)
- probably more issues
PS I hope this helps to diagnose the issue https://github.com/coverlet-coverage/coverlet/issues/1196. I have run more than 10 builds (with 10 tries), but all have the same issue 😦
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 17 (5 by maintainers)
I’m currently not that motivated to investigate that issue again, because I was waiting half a year for a release of my fix. Now, I switched (back) to MS coverage in my project… I do not have an idea except that Microsoft has changed some detail with .NET 8. IF I start investigation I would update the existing tests from net6 to net8.
It’s a ASP.NET Core 5 application with multiple projects.
I’m afraid it will take some time to create a repro.
Hi @304NotModified thanks for reporting this. We’ll take a look asap.
fixed in https://github.com/coverlet-coverage/coverlet/pull/1449
As additional information, I reproduce the problem in my library. Check the action associated with: https://github.com/adampaquette/Typely/pull/28.
I have the following structure: Typely.EfCore depends on Typely.Core. The project Typely.EfCore.Tests needs to instrument Typely.Core to fill the missing coverage on common functions.
Despite the fact that use publish+ref works I feel it too much as an “hack”, I prefer something more useful in every scenario. One idea I had also in past would be add a configuration that can be used by instrumentor for probing additional default directories. Something like
typesresolutionpathswhere a dev can in case of issues specify a list of path where to search if default paths don’t work.PreserveCompilationContextis used to emit information on deps files and help coverlet to try to resolve libs needed by Cecil.https://github.com/MarcoRossignoli/coverlet/blob/master/src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs#L173
If you’re able to provide a repro I can try to improve this one.
I am having the same issue:
As @304NotModified pointed out it seems that coverlet msbuild cannot find the DLL under
bin/Debug/.net5.0. Even though the DLL is available inbin/Debug/.net5.0/refs, things only work when I manually copy the DLL file to the parent folder,bin/Debug/.net5.0. Is it the case that coverlet needs to scan the /refs folder as well to prevent this type of issue?