rfgamaral
rfgamaral

Reputation: 16842

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

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...

Upvotes: 3

Views: 2338

Answers (6)

abhilash
abhilash

Reputation: 5651

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

Upvotes: 1

Hector Sosa Jr
Hector Sosa Jr

Reputation: 4250

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

Upvotes: 1

Jamie Penney
Jamie Penney

Reputation: 9522

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

Upvotes: 1

Ali Shafai
Ali Shafai

Reputation: 5161

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

Upvotes: 0

R. Martinho Fernandes
R. Martinho Fernandes

Reputation: 234474

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.

Upvotes: 0

John Saunders
John Saunders

Reputation: 161773

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.

Upvotes: 0

Related Questions