问题
Is there any way to remove unused types/code from a project.
lets say I'm using NAudio
(source code) in my console application and I'm only using the WaveIn
class from it. Is there any way for me to remove unused classes from the code and only keep the WaveIn
class and the classes WaveIn
depends upon? Something down the line of tree shaking
回答1:
Ndepend was the answer
from t in Types
let depth0 = t.DepthOfIsUsedBy("NAudioTrim.Program")
where depth0 >= 0 orderby depth0
select new { t, depth0 }
where NAudioTrim.Program
contains the entry point of my application and contains the used types.
Once you get the list of all used types and the types they use you can delete the rest of the files/types
来源:https://stackoverflow.com/questions/38822663/only-keep-used-types-and-remove-unused-types