Skip to content

Add option to set search directories for dependencies of instrumented modules #2014

Description

@viktorgobbi

Problem

When instrumenting assemblies that reference dependencies located in non-standard directories (e.g. satellite assemblies, shared native interop wrappers, or multi-project output layouts where DLLs are scattered across folders), Coverlet's Cecil-based assembly resolver only searches the directory that contains the module under instrumentation. This causes preflight resolution failures (UnresolvableDependencies) and prevents those modules from being instrumented, silently dropping them from coverage even though they are valid targets.
We have multiple projects that are extensions/addins for other products, many of the assemblies we reference are already loaded in the processes that loads our extension and therefore we avoid having these assemblies in the project output.

Proposed solution:

Add a new option, e.g. --coverlet-dependency-search-directory, that accepts one or more directory paths to be registered as additional search directories on the NetstandardAwareAssemblyResolver used during both preflight resolution checks and module instrumentation.

CLI (coverlet.MTP)

dotnet test -- --coverlet --coverlet-dependency-search-directory path\to\extra\dir1 --coverlet-dependency-search-directory C:\path\to\extra\dir2

Config file (coverlet.mtp.appsettings.json)

{
  "Coverlet": {
    "DependencySearchDirectories": "path\\to\\extra\\dir1,C:\\path\\to\\extra\\dir2"
  }
}

The directories are added to the resolver in both Instrumenter.Preflight() (so unresolvable-dependency skipping is accurate) and Instrumenter.Instrument() (so Cecil can fully read and rewrite the module).

We have some unit tests that cover the assembly loading behavior so copying the dependencies required for coverlet to instrument the assemblies is not possible as it changes the assembly loading behavior and therefore causes tests to fail.

I've implemented this for coverlet.mtp on my local environment (mainly with the help of copilot) and it seems to work fine, I get the full coverage now when I provide the missing dependencies coverlet needs to instrument all assemblies via the new parameter.

I'm happy to provide a pull request for this.

Activity

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

    driver-MTPIssue related to Microsoft Testing Platform driver

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions