Skip to content

microsoft/BogusDependencies

Repository files navigation

BogusDependencies provides common code for analyzing C# compiler and MSVC C++ linker outputs to determine which inputs are not actually necessary to building the final output. These bogus dependencies can then be surfaced in tooling to feed back to developers to help reduce package and project-to-project references. This reduces the complexity and depth of the build dependency graph along with reducing file I/O and processing during the build, resulting in lower overall build time.

This repo was created for Microsoft Hackathon 2020.

C++ Bogus Dependencies

The Microsoft C++ Linker includes a flag /VERBOSE:UNUSEDLIBS that writes additional information to stdout about .lib files that were unused. A similar flag /VERBOSE:UNUSEDDELAYLOAD can point to delay-load DLL references whose code was unused.

C# Bogus Dependencies

The C# compiler team committed a feature in 2019, Used Assembly References, that allows bogus dependency detection. See the issue. Feature documentation is here.

The feature exposes a new Roslyn analyzer API, GetUsedAssemblyReferences, to allow retrieving the assemblies that were actually used in generating the compilation output. Subtracting that list from the list of compiler input assemblies results in bogus assembly inputs.

Making Use of Bogus Dependency Information

For each bogus input, mapping to the source of the input can find one of:

  • A bogus project-to-project dependency if the input is generated by another project in the build. This feedback can result in either a developer making use of the input or cutting the dependency. Applied recursively, this could mean removing dead projects and code from a repo. The fastest build time is for code that is not compiled.
  • An unneeded package reference, e.g. to a Vcpkg C++ package or NuGet .NET package. This reduces compile/link I/O and CPU but does not change the build dependency graph. If this is the last such package reference, the package could be removed as a dependency of the repo, reducing build prep time by eliminating package pull requests.
  • An unneeded C++ SDK library reference that could be cut, reducing link I/O and CPU.

Related Work

  • https://github.com/dfederm/ReferenceTrimmer wraps an MSBuild execution and compares the assemblies pulled forward by RAR (MSBuild ResolveAssemblyReferences) to those referenced from proj-to-proj and package references, and recommends removals. The work in this repo can be combined with that work to make its recommendations much more robust, as without the Roslyn feature noted above, the compiler and RAR will leave behind referenced assemblies where only const values or interfaces were used, resulting in broken builds where packages or ProjectReferences were removed unnecessarily.

  • https://github.com/KirillOsenkov/CodeCleanupTools is a multi-tool with an option to clean up unused references.

Contributing

See Contributing.md.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published