Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "remove unused references/packages" #6763

Closed
Pilchie opened this issue Nov 13, 2015 · 26 comments
Closed

Support "remove unused references/packages" #6763

Pilchie opened this issue Nov 13, 2015 · 26 comments
Assignees
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it InternalAsk
Milestone

Comments

@Pilchie
Copy link
Member

Pilchie commented Nov 13, 2015

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.

@alrz
Copy link
Member

alrz commented Nov 14, 2015

Would this also uninstall corresponding nuget packages?

@Pilchie
Copy link
Member Author

Pilchie commented Nov 14, 2015

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.

@carlcom
Copy link

carlcom commented May 27, 2016

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

@CyrusNajmabadi CyrusNajmabadi added the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label Aug 23, 2017
@Korporal
Copy link

@Pilchie - Me too...#21672

@kendrahavens
Copy link
Contributor

Additional external ask: https://developercommunity.visualstudio.com/content/idea/540381/add-c-project-feature-to-remove-unused-references.html

@jinujoseph jinujoseph changed the title Support "remove unused references" Support "remove unused references/packages" Aug 9, 2019
@jinujoseph jinujoseph modified the milestones: Backlog, 16.3, 16.4 Aug 9, 2019
@davidhjones
Copy link

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

@ChristophWeigert
Copy link

Any update on this one?

@TheMrAnderson
Copy link

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.

@tuzumkuru
Copy link

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

@sercanparan
Copy link

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

@JoeRobich
Copy link
Member

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.

@kpranavk
Copy link

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.

@malcolmrs
Copy link

Any updates in this? Waiting eagerly

@CyrusNajmabadi
Copy link
Member

It's still being worked on.

@DennyOne
Copy link

DennyOne commented Apr 5, 2021

Hi, thanks for working on the Remove Unused References feature!

I used to use it in VB projects all the time and would like very much to see it in C#. I just installed 16.10 Preview 1 and made sure the option to show it is on; however, there is no menu item for this in the Project or References node context menus. This is a .NET Framework 4.8 project.

I don't see it in the Project or Dependencies node context menus in a .NET Core 3.1 project either. I changed it to target .NET 5 - still not there.

Thanks!

@ahdung
Copy link

ahdung commented Apr 26, 2021

hope it for multiple targets sdk project.

@Varorbc
Copy link

Varorbc commented Apr 26, 2021

Is it possible to remove duplicate dependency packages?

@jmarolf jmarolf added the User Story A single user-facing feature. Can be grouped under an epic. label Dec 2, 2021
@jmarolf jmarolf removed the User Story A single user-facing feature. Can be grouped under an epic. label Jan 6, 2022
@jasonmalinowski
Copy link
Member

@mikadumont @JoeRobich Should this be closed now?

@JoeRobich
Copy link
Member

Thanks @jasonmalinowski! Enhancements are being tracked in #50054

@DennyOne
Copy link

DennyOne commented Sep 8, 2022

It looks like it is in .Net6 projects but not .Net Framework 4.8 projects. If this is important enough, you can leave it open; otherwise you can close it. Please see images below, Thanks!


Visual Studio 2019 (Version 16.11.18) / .Net Framework 4.8 project / Solution Project menu
image

Visual Studio 2022 (Version 17.3.3) / .Net Framework 4.8 project / Solution Project menu
image

Visual Studio 2022 Preview (Version 17.4.0) / .Net Framework 4.8 project / Solution Project menu
image


Visual Studio 2019 (Version 16.11.18) / .Net Framework 4.8 project / References menu
image

Visual Studio 2022 (Version 17.3.3) / .Net Framework 4.8 project / References menu
image

Visual Studio 2022 Preview (Version 17.4.0) / .Net Framework 4.8 project / References menu
image


Visual Studio 2022 (Version 17.3.3) / .Net6 SDK project / Solution Project menu
image

Visual Studio 2022 Preview (Version 17.4.0) / .Net6 SDK project / Solution Project menu
image


Visual Studio 2022 (Version 17.3.3) / .Net6 SDK project / Dependencies menu
image

Visual Studio 2022 Preview (Version 17.4.0) / .Net6 SDK project / Dependencies menu
image

@DennyOne
Copy link

DennyOne commented Sep 8, 2022

Sorry, you closed it while I was preparing the comment! Why not wait a day or so for a reply before you close it?

@JoeRobich
Copy link
Member

Hi @DennyOne, the enhancement to support .NET Framework projects is tracked in #54801.

@malcolmrs
Copy link

malcolmrs commented Sep 11, 2022 via email

@DennyOne
Copy link

Hi @JoeRobich, thanks for letting us know of the .NET Framework tracking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it InternalAsk
Projects
None yet
Development

No branches or pull requests