Extending MSBuild

Extending MSBuild

If you're like me, you try to stay current on technologies. Not for the sake of currency, but because you want to be able to take advantage of the tools and infrastructure that can help you do your job better or faster. Along those lines, the .NET Framework v2.0 includes tons of new goodies that extend the capabilities of your toolbox: a serial I/O library, secure strings, lots of new stuff in ASP.NET for web apps, 64-bit capability, generics, lots of new goodness for web services. So from my perspective, there's some good stuff in the base framework.

Beyond that, lots of developers consider the tool itself to be the first-order factor - if the IDE is better, they are more productive. Microsoft tried to deliver VS2005 as a significant advance over VS2003. If you want to try it out, check out the "Express" versions of Visual Studio, a free (as in beer) download. What have you got to lose?

One of the hidden gems in VS2005 is msbuild - this is the new build engine. In fact it's so good, this is one of things that motivated my upgrade to .NET 2.0.

If you come from C and Unix like me, you know makefiles. If you come from Java you may be familiar with Ant. MSBuild is "nmake on steriods", and is similar to Ant, but it works with multiple .NET languages. It is similar to nAnt, but is integral to Visual Studio. When you press F5 in VS2005, the build that kicks off is actually using MSBuild.

The really cool part about MSbuild is the extensibility. If you modify the build file to inject additional steps into the build, then VS will perform your additional custom steps. You can insert a step that says Doh! when the build fails. You can do anything you want. Send a mail message, produce a PDF report. All of the above.

The other nice thing: MSbuild works outside of VS2005. In fact MSBuild.exe is included in the free .NET Framework 2.0 runtime. You don't need to install a version of Visual Studio to get it. So if you like to work on projects in a text editor (emacs, slickedit, whatever), then you can still run your builds with msbuild. AND... the projects you define in MSbuild can be loaded into VS2005 at some later point. Nice!

Around extensibility, there is a community of sites cataloging extensions to msbuild. Tigris has one. These extensions do stuff like Subversion or VSS check-in/out, ftp stuff, SQL stuff, registry operations, HTTP downloads, etc. And it's really easy to build your own extensions in managed code.

Some links on msbuild: Don Box: msbuild for makefile converts MSDN TV episode on MSBuild Converting nAnt tasks to MSBuild Customize your Builds MSBee: a toolkit that enables you to build .NET 1.1 projects with MSBuild.