MSBuild: A Real-World Recursive Application

I recently posted on this blog a “toy application” of MSBuild that calculates factorials. Well, this weekend I was working on the new build script for the Nito.Async library, and surprised myself by finding an actual real-world application for this code!

It turns out that this is useful when autogenerating publisher policies. Nito.Async follows a simple major.minor version numbering scheme, where changes in minor are always fully backwards-compatible and changes in major never are. Publisher policies are a way of declaring backwards compatibility for strongly-named assemblies in the GAC (more info on MSDN and in KB891030).

To autogenerate publisher policies for a version maj.min, the build script must build a separate dll for each version in the range [maj.0, maj.min). It turns out that the recursive behavior in my “factorial.proj” toy was exactly what I needed; I just changed the return value to concatenate a list of numbers instead of multiplying them together.

There was one other small hurdle to overcome; I had to perform a cross product of two different item groups (the list of “previous minor versions” and the list of library dlls). This is not exactly straightforward in MSBuild, and is a common question (just Google for “MSBuild cross product”).

The updated build script for Nito.Async has been checked into CodePlex, so if you want to see the details on how this works, you can view it online here. I’m not going to post it on the blog here, for sake of space.