On larger and/or long running projects, I tend to reference many assemblies and namespaces, and often I end up removing some functionality later on or moving it into a different project.
I just wonder, is there a way to check every project (heck, every .cs file) in my whole Visual Studio solution and get a list of all referenced Assemblies and Namespaces that are not actually being used and can be safely removed? I know that ReSharper can do it for a single Code File, but I did not see an option to check all files or to check for unneeded Assemblies.
Using Visual Studio 2005 and 2008 Professional if that matters.
Edit: Thanks so far. The Problem with ReSharper or "Remove and Readd if build breaks" is that it's quite tedious on every single file and assembly (My project has about 120 .cs Files in 7 Assemblies, and references a total of 18 Assemblies outside of the solution), so ideally i'm looking for something "one-click". Big Bonus points for some automatic way that can be used in buildscripts to generate a report :)
CTRL + K + E Will sort and remove your unused usings.
Navigate to Tools > Options > Text Editor > Code Cleanup. Add a check in the "Run Code Cleanup profile on Save." Be sure to select the appropriate profile you want to execute automatically whenever you save!
Use ReSharper or similar code analysis tool to identify any unused references in your projects and uninstall the nuget in the corresponding projects. Sometimes uninstalled nugets still linger in the Installed packages and Updates lists in the Manage NuGet Packages dialog.
Removing unused references is a feature Visual Studio 2008 already supports. Unfortunately, only for VB .NET projects.
I have opened a suggestion on Microsoft Connect to get this feature for C# projects too:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=510326
If you like this feature as well then you might vote my suggestion.
I found this question while searching in Google and looking for a way to remove unused "Using" statements from my code.
Refactor is great, but it isn't available to me. However, as it turns out Visual Studio 2008 does this on its own.
Here are the steps:
Done. I realize this doesn't answer the original question (doing this en masse for an entire project) but it does answer my question.
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