Transforming the CLR to numerical applications, and the nullspace that results.

Wednesday, July 2, 2008

Generate AssemblyInfo.cpp for C++/CLI

I manage a number of C++/CLI projects (which, for the most part, is a decent language extension, contrary to the expected detractors' views). For my C# projects, I enjoy being able to create the AssemblyInfo.cs file on the fly from properties I store in my SVN repository. It allows me a sort of "poor man's product management" where I can manage product name, description and major.minor version in one place, versioned along with the code.

This was easy using NAnt. I've recently been moving to MSBuild and have been sharing the same sort of view as my former colleague Travis Illig: NAnt is way more flexible and easy out of the box. On the other hand, as Scott points out in that post, much of it is a matter of learning the "MSBuild way" where Tasks and Targets are much more independent as well as adding some custom tasks to replace the missing ones from NAnt.

Enter the very nice collection called MSBuild Community Tasks. It filled in for the AssemblyInfo task I loved in NAnt. However, I got no such love from it for C++/CLI. MSBuild Tasks are quite easy to create, however (easier, even, than NAnt tasks, since fewer attributes are needed). I looked over the source for the custom AssemblyInfo task, and found it to be very easy to modify. Taking advantage of the CppCodeProvider which is new for .Net 2.0, I added C++/CLI support to it, added some tests, and contributed the patch back to the project. Paul Welter reviewed and applied it astonishingly quickly. Something I could learn from for SharpMap (before you complain, however, notice I said I included tests and a patch file ;) )...

So, if you're looking for an AssemblyInfo.cpp generator, or a number of other useful custom tasks, look no further than the well-tended MSBuild Community Tasks project.


Scott said...

There is also a newer opensource library called MSBuildContrib (

Bronumski said...

I got the latest trunk to try your changes but I am having a problem. The output has the attributes before the using statements and therefore doesn't work. Is it something wrong with my setup?