detecting assembly references we don't directly depend on

Topics: Metadata Model, PE reader
Aug 22, 2010 at 1:08 PM
Edited Aug 22, 2010 at 1:11 PM


Let's say *some* compiler is given more assembly references (in the command-line) than actually needed for the compiled program to run (this happens all the time in Visual Studio). 

While emitting bytecode, the compiler could keep track of external types actually used. Has been the algorithm for that documented somewhere? 

At least one tool (NDepend) tells which assem-refs to prune,

In case the link above doesn't work:


So I know that it's possible :) Anybody been there before?



Aug 30, 2010 at 5:42 AM

If you give PeWriter an assembly with list of assembly references that does not include all of the assemblies actually referenced, it will add the missing references. Thus, given an assembly with an empty list of references, you'll get exactly those references that you need.

The algorith used is simply to traverse the object model and to enter each assembly reference encountered into a table.