Is it possible to remove unused code/assemblies in .NET?

妖精的绣舞 提交于 2020-01-13 18:08:52

问题


I have a control library in my application that's a bit big for the type of application I'm developing. The library is more than 2Mb and I barely use it's functionality, I would say I use like 5% to 10% of all it's functionality.

Is there anyway to remove code that my application never uses from the library?

P.S: The library is not developed by me and it's not open-source (you can buy the code though).

EDIT: I posted this because I though this could be achieved using ILMerge, that's what someone said to me in the past... I tried to use ILMerge but didn't work and I'm not sure I'm using it right...


回答1:


My boss worked with an obfuscation product that did this, by bringing the code that was used into a combined assembly. Can't remember what it was called though, might have been DotNet Reactor (we used a few different products before settling on one).




回答2:


There's a product called SmartAssembly that does this. It's a bit pricey, at least for me.




回答3:


Just as a caveat, make sure what you are doing is permissible according to the EULA of the vendor company which made library.




回答4:


2Mb is not large.

If you feel it's too much, and since it's your code, you should consider refactoring it into separate assemblies, still using the same namespaces. That way, your code could reference only the assemblies it needs.




回答5:


If it's open source you can take a look at the code and selectively take out what you want and build a separate assembly.

If it's not open source you can use Reflector on the assembly and wring out the code you want to keep (and all its dependencies) and then rebuild it in your own assembly. I'm not sure how legal that is. It probably depends on the license of your library.




回答6:


You can do that, but needs some programming. take a look at mono cecil project, you can open the assembly, remove the unwanted types and save it. the programming is involved with determining what types are not used (type A is using type B, so if YOU use type A, you should keep type B)...



来源:https://stackoverflow.com/questions/850672/is-it-possible-to-remove-unused-code-assemblies-in-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!