Skip to content

Support "remove unused references/packages"  #6763

@Pilchie

Description

@Pilchie

Before VS2015, VB suppported a "Remove unused references" button in it's property pages, but that was never implemented as part of Roslyn.

Reported in http://connect.microsoft.com/VisualStudio/feedback/details/2005014/unused-references-button-missing-from-visual-studio-2015 and internal bug 163717.

User Scenario
Users should be able to

see unused assemblies, packages, and project references
remove unused references
Design

  1. Provide a compiler level API to list used (or the opposite unused) references per compilation #37768 The compiler team will provide an API to list used references in the compilation (or the same: unused references in the compilation). These are individual assembly references.

  2. Provide a map file generation to use for remove unused references functionality sdk#10414 The build team will generate a file with a map of assemblies, packages which can be checked for usage/non-usage. MS Build will generated the file. If other environments are used, they have to provide this file on their own.

  3. Provide project-system API to remove unused references (assemblies, packages) project-system#5258 The project-system team will provide an API for fixing issues.

  4. Implement an analyzer to remove unused references #37769 The IDE team will look for both the compiler API, the file generated and the project-system API, and provide an analyzer with a fixer that will report references which can be removed.

  5. The project-system team will help with driving UI implementation. It can be grey out references with actions in the context menu or a special user control like one described below. This can be decided later based on restrictions found on previous steps.

UX Model
The functionality should be available in the Solution Explorer. In an ideal case, we should grey out unused references directly in the Solution Explorer (dotnet/project-system#76) and add an option in the context menu to remove them. If this is not available e.g. due to performance reasons, please see the UX model below.

Here is the UX model in case if we cannot arrange this directly in the Solution Explorer:

  1. In the Solution Explorer right click on either a project, a solution or the References node of a project.

  2. Have 2 of the following options:
    A. Right-click the selection and choose an option to Remove Unused References in the context menu.
    B. Or a keyboard shortcut to Remove Unused References.

  3. When selecting Remove Unused References have a dialogue that displays all references that have no actual usages in source code in a tree view grouped by projects. By default, all references are selected for deletion. If necessary, deselect references that you want to keep.

image

Then select update to remove the unused references/nuget packages.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions