Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it not possible to remove unused references in C#

Is there any reason for it is not possible with Visual Studio to remove unused references (to projects and assemblies) in C# and C++ projects while it is possible to do so from a Visual Basic project (see here)?

I know you can do it with other tools like Resharper, I was just wondering if there was any technical reason for not being able to do this in C# and C++ projects? Or did Microsoft just choose it to work like that. It seems to be a quite useful feature.

like image 533
Simon Fischer Avatar asked Feb 18 '11 10:02

Simon Fischer


People also ask

How do I get rid of unused Visual Studio?

CTRL + K + E Will sort and remove your unused usings.

How do I remove unused NuGet packages?

Clean up project references and NuGet packages in Visual Studio. Firstly, Right Click on the Project, and select “Remove Unused References”. This will bring up the “Remove Unused References” Dialog that shows the projects and all unused packages. Here, you can again choose if you want to remove them or keep it as it is ...

How do you delete unused variables in Visual Studio 2017?

You can use ReSharper. It will mark all unused variables and allow you to remove them.


1 Answers

Note that the compiler will automatically drop any unused references from the assembly, so at the assembly metadata level this is redundant. It then just becomes an IDE/tooling issue. Would it be impossible? no (although obviously it would need to keep any that are marked for copy-local, to ensure it gets deployed). We can probably assume, therefore, that it is simply a "time to implement vs utility" (compared to other more useful things that could be done).

I'm sure you could write an IDE extension for it if you wanted ;p

like image 61
Marc Gravell Avatar answered Sep 24 '22 07:09

Marc Gravell