Removing all unused references from a project in Visual Studio projects

前端 未结 14 2023
北荒
北荒 2020-11-29 16:41

I just wondered if it possible within various Visual Studio versions to automatically remove all references from a project that were never been used?

In your answer,

相关标签:
14条回答
  • 2020-11-29 17:08

    Using DevExpress, I follow these instructions:

    1. In VS, go to DevExpress - Editor - Code Cleanup. Under Rules, check 'Remove unused namespace references'. Click OK.
    2. Right-click on the solution, and choose 'Code Cleanup'. The cleanup runs for a few minutes, and finishes.
    3. Build your application
    0 讨论(0)
  • 2020-11-29 17:14

    For anybody coming here looking for Visual studio 2012:

    Download and Install Reference Assistant for Visual Studio 11

    Later you can do:

    enter image description here

    0 讨论(0)
  • 2020-11-29 17:16

    In a Visual Basic project there is support to remove "Unused References" (Project-->References-->Unused References). In C# there isn´t such a function.

    The only way to do it in a C# project (without other tools) is to remove possible unused assemblies, compile the project and verify if any errors occur during compilation. If none errors occur you have removed a unused assembly. (See my post)

    If you want to know which project (assembly) depends on other assemblies you can use NDepend.

    0 讨论(0)
  • 2020-11-29 17:18

    Some people suggested to use an awesome tool - Reference Assistant for Visual Studio. The problem is that VS2012 is the latest supported Visual Studio. But there is the way to make it work in VS2013 as well ;)

    And here is how:

    1) Download Lardite.RefAssistant.11.0.vsix

    2) Change the extension to zip: Lardite.RefAssistant.11.0.vsix -> Lardite.RefAssistant.11.0.zip

    3) Unzip and open the extension.vsixmanifest file in the text editor

    4) Find all occurences of InstallationTarget Version="[11.0,12.0)" and replace them with InstallationTarget Version="[11.0,12.0]" (note the closing bracket)

    5) Save the file and zip all files so they are on the root zip level

    6) Change the extension of the new zip to vsix

    7) Install and enjoy :)

    I've tested it with VS2013, thanks source for the tutorial

    EDIT Add to support VS 2015 Community Edition

    <InstallationTarget Version="[14.0,15.0]" Id="Microsoft.VisualStudio.Community" />
    

    Meaning of the brackets

    [ – minimum version inclusive.
    
    ] – maximum version inclusive. 
    
    ( – minimum version exclusive. 
    
    ) – maximum version exclusive.
    
    0 讨论(0)
  • 2020-11-29 17:19

    You can try the free VS2010 extension: Reference Assistant by Lardite group. It works perfectly for me. This tool helps to find unused references and allows you to choose which references should be removed.

    0 讨论(0)
  • 2020-11-29 17:19

    You can use Reference Assistant extension from the Visual Studio extension gallery.

    Used and works for Visual Studio 2010.

    0 讨论(0)
提交回复
热议问题