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.
CTRL + K + E Will sort and remove your unused usings.
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 ...
You can use ReSharper. It will mark all unused variables and allow you to remove them.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With