Home >

What is a build script? Writing MsBuild Scripts - Part I

6. July 2009

I was thinking of writing post series on NAnt but then I decided to write some on MsBuild first.

This post will briefly introduce you the basic concepts of automation of build, why we need build tools/scripts, and what alternatives we have.

Let’s first start with the definition of build script/tool.

What is a build script?

A build script is all about automation. When we compile projects, we also want to perform some other steps such as running tests, compiling documentation, create an examples package, move some files from one location to another, and in the end zip them, or create an installer for the project. Doing them by hand is not really an option, and you may have thought of preparing a batch file/shell script before you learnt the build files.

For me, Makefile was the first place that I heard about the term “build script”. It is mainly used in Linux to compile applications.

When we take a look at a sample makefile


OBJS = main.obj io.obj
CC = bcc
MODEL = s
CFLAGS = –m$(MODEL) 



project.exe : $(OBJS) tlink c0$(MODEL) $(OBJS), $(.TARGET),, c$(MODEL) /Lf:\bc\lib main.obj : main.c $(CC) $(CFLAGS) –c $(.SOURCE) io.obj : io.c $(CC) $(CFLAGS) –c $(.SOURCE) $(OBJS) : incl.h

First we have several properties which we’ll use later, they are like variables.
Then we have some targets which has “:” on the right. On the right of “:”, we have their “dependencies”. A dependency is a unit that has to be run before the dependent, or a file that our file depends on. For example, main.obj depends on main.c and in case main.c is modified, we will run that target again. The lines after the target are the commands which will be run as part of the target.

This dependency idea is key to every build system and main points in writing a build script is to find dependencies of your project. After you define them, the rest is a piece of chocolate cake!

OK, i spoke too much Linux for a .net blog :) Let’s turn to our beautiful .net World.

In .net world, there are 2(AFAIK, if not please comment) build tools written specifically for .NET. One is the famous NAnt, and the other is MsBuild. NAnt is usually used in OpenSource project. MsBuild is being used since VS 2005, and it is part of the framework. Your csproj files are actually MsBuild files.

Most people say that that nant is more flexible and mature, but they also say that the nativeness of MsBuild into visual studio is a plus. Some they say that they delegate the build to MsBuild while using Nant for other stuff.

In the next post, we’ll write(and use .csproj) a basic MsBuild script.

Comments

8/24/2010 1:37:39 PM #
Really great post are you going to include more on Nant next time? still very interesting though

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading