I’ve been spending a bit of time spelunking around MSBuild internals, and as part of the process I’ve needed to build up a little bit of a mental map of the built-in targets and their dependencies. As a bit of an excercise I decided I would load up a project file using the object model in the Microsoft.Build.BuildEngine namespace and then render the relationships between the targets. Here was the output of my first attempt.
Admittedly its not the most readable diagram, and about the only thing you can really appreciate from it is that its C-O-M-P-L-E-X. Notice the smudge on the top left hand corner? Thats the text of the overlapping rectangles that I couldn’t be bothered dragging out manually.
I actually whipped this up in about fifteen minutes and leveraged the Netron library to do the graphical work. Its actually pretty neat, but because I used the Netron Light version it doesn’t include things like automatic layout etc. I’m not real proud of the code (don’t judge me by it), but it is functional if a little ugly. The whole excercise did leave me with a couple of questions though:
- What is the easiest way to expand properties programatically? My reflection-code ain’t it.
- Why aren’t Project.DefaultTargets and Target.DependsOnTargets exposed as a TargetCollection instead of a string? I suspect it might have something to do with property expansion.
- What is another question I could ask here?