I am in the process of evaluating the NDepend tool for a client of mine, and was wondering if anyone could provide assistance with the following query:
// <Name>Potentially dead Assemblies</Name>
warnif count > 0
from a in JustMyCode.Assemblies where
a.NbTypesUsingMe == 0
select a
Although this provides a large list, I would also like to check if the only reference is from a test project such as MyNamespace only referenced by MyNamespace.Tests.
How could this be done? I have not found documentation on creating a IsUsedBy that does not take a constant.
Sincerely,
Martin
For matching dead assemblies, you don't need to count types but just to count assemblies using me:
warnif count > 0
from a in JustMyCode.Assemblies where
a.AssembliesUsingMe.Count() == 0
select a
If you want to match a condition on types using an assembly you can write something like:
warnif count > 0
from a in JustMyCode.Assemblies
let typesUser = Application.Types.Using(a)
where typesUser.Count() == 0 ||
typesUser.ParentNamespaces()
.WithNameWildcardMatchNotIn("MyNamespace.Tests*").Count() == 0
select a
Notice how in this previous query we don't even iterate on typesUser (with a typesUser.Where(t => ...)
), but instead we use NDepend.API set methods like WithNameWildcardMatchNotIn().