Even a chimp can write code

Sunday, July 10, 2005

Building an Avalon application: Part 1

After our look at Avalon's Deployment story, let's look at it's Build mechanism. Avalon relies on the Microsoft Build engine (MSBuild) at the core of it's build infrastructure. Before we jump into looking at Avalon Build, it would be worthwhile to get a refresher on MSBuild.

MSBuild is the new build platform for Microsoft and Visual Studio. It is completely transparent with regards to how it processes and builds software, enabling developers to orchestrate and build products in build lab environments where Visual Studio is not installed. The MSBuild engine synchronously executes a project file i.e. an XML file composed of a series of targets with pre-defined execution order, each target consisting of zero or more tasks.

Those familiar with Ant and its .NET clone NAnt, probably see the similarities. For others, the following couple paragraphs should serve to illustrate how targets and tasks help build applications.

For example, here's a simple project file with one target BuildMyApp that compiles HelloWorld.cs using the task CSC into the assembly HelloWorld.exe.

<Project DefaultTargets="BuildMyApp"
<Compile Include="HelloWorld.cs" />

<Target Name="BuildMyApp">
<CSC Sources="@(Compile)"

If the project file were named MyFirstApp.csprojyou may run this by specifying this on the command line:

msbuild MyFirstApp.csproj

MSBuild ships with the .NET runtime. This means if you have the .NET Framework, you can compile a typical application. Let us look at the important constituents of MSBuild as relevant to building Avalon applications:
MSBuild.exeThe console application that consumes project files. Any C# or VB project you create in VS can be passed to MSBuild.exe to be built from the command-line.
Microsoft.Build.Engine.dllIs the common build engine responsible for reading in and executing build scripts.
Microsoft.Build.Tasks.dllcontains MSBuild tasks which are discrete, reusable build components. For example, there’s a CSC task for invoking the C# compiler.
PresentationBuildTasks.dllContains Avalon's MSBuild tasks. These include MarkupCompilerPass1, MarkupCompilerPass1, FileClassifier, ResourcesGenerator etc.
Microsoft.Build.Utilities.dllOffers a set of utilities classes that you would use if you were to write your own custom tasks.
Microsoft.Build.Framework.dllContains a set of interfaces that define the way the engine talks with tasks and loggers.
Microsoft.Build.Conversion.dllContains classes that help convert legacy VS .NET 2003 project formats to VS 2005 (Whidbey) MSBuild formats.

Microsoft ships a bunch of .targets files that you may enlist in building your project. For example:

  • Microsoft.Common.targets: A repository of common targets, the bulk of the build work is done in this file.

  • Microsoft.CSharp.targets: This contains C# build logic

  • Microsoft.VisualBasic.targets: This contains VB build logic

  • Microsoft.WinFX.targets: Here's where all of the Avalon Build logic resides. This targets file does not ship with the .NET Framework runtime, instead gets installed on WinFX setup.

The Avalon Build pipeline employs a number of these targets and tasks to build Express or Installed applications. The pipeline looks something like this:

MarkupCompilerPass1 -> FileClassifier -> ResourcesGenerator (for Main assembly) -> CSC -> MarkupCompilerPass2 -> ResourcesGenerator (for Satellite assembly) -> AL -> CopyToOutput.

If you don't have a clue what this is, don't sweat. We will look at the Avalon Build process in more detail in future posts.


Email this | Bookmark this