编译器只编译可以得到执行的代码? [英] Will the compiler only compile code that can get executed?

查看:190
本文介绍了编译器只编译可以得到执行的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类库,我只使用它的一部分。有没有需要删除什么是没有使用,以缩小创建的代码的大小(在发布配置)?

I have a class library and am using only part of it. Is there a need to delete what isn't being used in order to shrink the size of the created code (in release configuration)?

据我所见,编译器负责处理,删除代码不会改变EXE文件的大小。这将永远是真的吗?删除所有不需要的代码需要很长时间,所以我想知道是否有需要。

As far as I've seen, the compiler takes care of that, and removing the code doesn't change the EXE file size. Will this always be true? Removing all unneeded code would take very long, so I want to know if there's need for that.

更多信息:在类库中有方法和类, t从执行代码调用,但被类库中的其他代码部分引用(它们本身从不被调用)。

More information: there are methods and classes in the class library that aren't called from the executing code, but are referenced by other parts of code in the class library (which themselves are never called).

推荐答案

p>否,编译器也包括死代码。一个简单的原因是,它不总是可能知道什么代码将和不会被执行。例如,即使一个从未被引用的私有方法也可以通过反射来调用,而且公共方法可以被外部程序集引用。

No, the compiler includes the "dead" code as well. A simple reason for this is that it's not always possible to know exactly what code will and won't be executed. For example, even a private method that is never referenced could be called via reflection, and public methods could be referenced by external assemblies.

你可以使用一个工具来帮助你查找和删除未使用的方法(包括仅由其他未使用的方法调用的方法)。尝试什么工具和技术您使用在.NET中找到死代码?查找未使用的代码,让您开始。

You can use a tool to help you find and remove unused methods (including ones only called by other unused methods). Try What tools and techniques do you use to find dead code in .NET? and Find unused code to get you started.

这篇关于编译器只编译可以得到执行的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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