Visual Studio: 检测不需要的Assemblies[英] Visual Studio: Detecting unneeded Assemblies

本文是小编为大家收集整理的关于Visual Studio: 检测不需要的Assemblies的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

在较大和/或长期运行的项目中,我倾向于参考许多组件和名称空间,并且通常以后在以后删除某些功能或将其移至另一个项目.

我只是想知道,是否有一种方法可以在我的整个Visual Studio解决方案中检查每个项目(Heck,每个.cs文件),并获取所有实际上未使用的参考组件和名称空间的列表,并且可以安全地删除?我知道Resharper可以为一个代码文件做到这一点,但是我没有看到检查所有文件或检查不需要的程序集的选项.

使用Visual Studio 2005和2008 Professional(如果很重要).

编辑:到目前为止,谢谢. Resharper或"如果构建中断(如果构建断裂)的问题"的问题在于,它在每个文件和组件上都非常乏味(我的项目在7个组件中有大约120个.cs文件,并且参考了解决方案以外的18个组件),因此,理想情况下,我正在寻找"一键式"的东西.可以在buildscript中使用的某种自动方式的大奖金积分来生成报告:)

推荐答案

resharper 将为您做到这一点,您可以在清洁中设置它您可以在宽解决方案中运行的代码选项; o)

其他推荐答案

如果您具有重音手机,请选择解决方案,右键单击并选择清理代码.然后,Resharper将通过解决方案中的每个代码文件.

关于删除项目参考,当编译器运行时,如果没有代码使用该dll.

,则不会添加参考

其他推荐答案

如果您已经安装了重音器,则可以从解决方案资源管理器中右键单击参考,然后单击查找依赖代码.如果它带有结果对话框,则您正在使用该参考/汇编.如果您获得"未找到的模块名称​​模块名称"的消息.然后,您应该可以删除该参考/组件,因为它没有使用.

本文地址:https://www.itbaoku.cn/post/13469.html

问题描述

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 :)

推荐答案

Resharper will do this for you and you can set it up in the Clean Code option that you can run solution wide ;o)

其他推荐答案

If you have ReSharper then, select the solution, right click and select cleanup code. Resharper will then go through every code file in the solution.

As to removing project references, when the compiler runs it won't add the reference if no code uses that dll.

其他推荐答案

If you have ReSharper installed, then from within the Solution Explorer you can right-click on a reference and click Find Dependent Code. If it comes back with a dialog of results then you're using that reference/assembly. If you get the message "Code dependent on module module name not found." Then you should be OK to remove that reference/assembly because it's not being used.