Reputation: 22466
I have a need to identify only the dlls that are used. Let me explain.
If you have a .Net exe, MyEXE.exe, for example, that references DLLA.dll, and DLLA.dll is a library of common functions that references 17 other DLLs, then during the build .Net will put all 17 along with DLLA.dll in the MyEXE.exe's bin folder. Even if MyEXE.exe only calls code that is used in 2 of the dlls referenced by DLLA.dll.
A .net app will run just fine with missing dlls as long as the entry assembly does not directly or indirectly call any functionality in the missing dll.
So I want to find the ones which are used.
I don't want to hard code this per project, thanks. I'd like an algorithm that I can run on any project. Thanks.
Upvotes: 1
Views: 70
Reputation: 755447
This isn't really a solvable problem in .Net. The general case is straight forward and is described by the following algorithm:
This will put all of the actual needed assemblies into the "needed set".
This is a fairly exhaustive search but misses a number of items
All of these represent dynamic method calls which can't realistically be analyzed by a static checker. Any of these could cause one of the other 17 DLLs to be used and hence break your deployment.
Instead of trying to statically detect the necessary set of assemblies (unsolvable) I would try and refactor the code so that the needed subset doesn't bring in so many DLLs
Upvotes: 1