Roslyn: Support "remove unused references/packages"

Created on 13 Nov 2015  路  14Comments  路  Source: dotnet/roslyn

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. 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. https://github.com/dotnet/sdk/issues/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. dotnet/project-system#5258 The project-system team will provide an API for fixing issues.

  4. 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 (https://github.com/dotnet/project-system/issues/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.

Area-IDE Feature Request InternalAsk help wanted

Most helpful comment

Well, since everyone is asking about it, this feature is in active development. So far, the Compiler team has completed their necessary work, the Project System team is getting in the last of their changes, and I have begun implementation of the analysis. After that will be UI work to display this information and allow the removal of references. So, we are seeing the light at the end of the tunnel for this feature.

All 14 comments

Would this also uninstall corresponding nuget packages?

Well, as implemented in VS2013 and before it did not, but I think if we were going to bring the feature back we would want it to understand NuGet.

I am in messy reference hell. This feature is long overdue.

this would be extremely helpful with moving
to aspnetcore 3 - it is mostly about package references..

I also think this would be very useful in allowing developers who join new projects to easily refactor code and cleanup dependencies they no longer need. Sometimes ripping out code can cross several projects and it would be nice to not have to one by one test removing a reference and seeing its impact.

Currently moving to .netcore3. This would be extremely helpful. Any update?

Any update on this one?

Any update? Devs shouldn't have to pay for ReSharper to get this functionality and face the performance hit that entails. This has been open for 5 years. Come on already.

Is there any update? Is this such a hard thing to develop?

I totally agree with @TheMrAnderson. Can't wait to hear from @JoeRobich soon. :)

Well, since everyone is asking about it, this feature is in active development. So far, the Compiler team has completed their necessary work, the Project System team is getting in the last of their changes, and I have begun implementation of the analysis. After that will be UI work to display this information and allow the removal of references. So, we are seeing the light at the end of the tunnel for this feature.

I am sooo much waiting for this feature as well :) I think of this every day and wish it was already there by now. I have installed Resharper so many times for this specific feature and uninstalled for other performance reasons.

Was this page helpful?
0 / 5 - 0 ratings