删除未使用的引用(="!使用") [英] Remove unused references (!= "using")

查看:193
本文介绍了删除未使用的引用(="!使用")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能找到并删除在我的项目未使用的引用?

How can I find and delete unused references in my projects?

我知道你可以轻松地删除在VS 2008的using语句,但这并不在你的项目中删除实际参考。引用的DLL仍将被复制到你的bin /安装包。

I know you can easily remove the using statements in vs 2008, but this doesn't remove the actual reference in your projects. The referenced dll will still be copied in your bin/setup package.

推荐答案

*注:参见<一href="http://www.jetbrains.net/devnet/message/5244658">http://www.jetbrains.net/devnet/message/5244658另一个版本的答案。

*Note: see http://www.jetbrains.net/devnet/message/5244658 for another version of this answer.

读通过的职位,它看起来像有一些混乱,原来的问题。让我来一刀吧。

Reading through the posts, it looks like there is some confusion as to the original question. Let me take a stab at it.

原来的职位实在是问这个问题:我如何识别和删除从一个Visual Studio项目引用其他项目/组件是不用呢?海报希望组件不再出现作为构建输出的一部分。

The original post is really asking the question: "How do I identify and remove references from one Visual Studio project to other projects/assemblies that are not in use?" The poster wants the assemblies to no longer appear as part of the build output.

在这种情况下,ReSharper的可以帮助你的确定的他们,但是你要的删除的他们自己。

In this case, ReSharper can help you identify them, but you have to remove them yourself.

要做到这一点,打开INTH解决方案浏览器,鼠标右键点击每个引用的程序集的引用,并选择查​​找相关code。参见:

To do this, open up the References inth Solution Browser, right mouse click on each referenced assembly, and pick "Find Dependent Code". See:

<一个href="http://www.jetbrains.com/resharper/features/navigation_search.html#Find_ReferencedDependent_$c$c">http://www.jetbrains.com/resharper/features/navigation_search.html#Find_ReferencedDependent_$c$c

您要么获得:

  1. 之间的依赖关系上参考在浏览器窗口的列表,或

  1. A list of the dependencies on that Reference in a browser window, or

未找到code依赖于模块XXXXXXX。一个对话框,告诉你。

A dialog telling you "Code dependent on module XXXXXXX was not found.".

如果你得到的第二个结果,你可以右键点击鼠标参考,选择删除,并从项目中删除它。

If you get the the second result, you can then right mouse click the Reference, select Remove, and remove it from your project.

虽然你非要在这段手动,即一个参考的时间,它会完成这项工作。我希望听到它是怎么做。如果任何人有某种方式自动这一点。

While you have to to this "manually", i.e. one reference at a time, it will get the job done. If anyone has automated this in some manner I am interested in hearing how it was done.

您可以pretty的多少忽略了那些在.Net框架,因为他们通常不被复制到您的生成输出(通常 - 但不一定是真正的Silverlight应用程序)。

You can pretty much ignore the ones in the .Net Framework as they don't normally get copied to your build output (typically - although not necessarily true for Silverlight apps).

有些职位似乎是回答这个问题:我如何删除使用从解决该文件中的任何引用不需要的来源$ C ​​$ C文件中的条款(C#)。

Some posts seem to be answering the question: "How do I remove using clauses (C#) from a source code file that are not needed to resolve any references within that file".

在这种情况下,ReSharper的并在几个方面帮助:

In this case, ReSharper does help in a couple ways:

  1. 在对动态错误检测标识未使用的使用条款为您服务。它们显示为code检验警告 - 该code会出现灰色的(是默认值)的文件中,并ReSharper的将提供一个提示将其删除:

  1. Identifies unused using clauses for you during on the fly error detection. They appear as Code Inspection Warnings - the code will appear greyed out (be default) in the file and ReSharper will provide a Hint to remove it:

<一个href="http://www.jetbrains.com/resharper/features/$c$c_analysis.html#On-the-fly_Error_Detection">http://www.jetbrains.com/resharper/features/$c$c_analysis.html#On-the-fly_Error_Detection

允许您自动将其取走的code清理过程的一部分:

Allows you to automatically remove them as part of the Code Cleanup Process:

<一个href="http://www.jetbrains.com/resharper/features/$c$c_formatting.html#Optimizing_Namespace_Import_Directives">http://www.jetbrains.com/resharper/features/$c$c_formatting.html#Optimizing_Namespace_Import_Directives

最后,实现ReSharper的做您的解决方案的静态code分析。所以,如果你有一个动态参考大会 - 比如通过反射或在运行时动态通过接口加载和访问的组件 - 它不会把它捡起来有不可替代的理解你的code碱基,并为你的工作在你的项目中的项目依赖。我发现ReSharper的功能非常有用。

Finally, realize that ReSharper does static code analysis on your solution. So, if you have a dynamic reference to the assembly - say through reflection or an assembly that is dynamically loaded at runtime and accessed through an interface - it won't pick it up. There is no substitute for understanding your code base and the project dependencies as you work on your project. I do find the ReSharper features very useful.

这篇关于删除未使用的引用(=&QUOT;!使用&QUOT;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆