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

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.

 

If you like the post, please kick it and shout it.

kick it on DotNetKicks.com
Shout it


Posted 07-05-2009 9:36 PM by Tuna Toksoz
Filed under: ,

[Advertisement]

Comments

DotNetKicks.com wrote What is a build script? Writing MsBuild Scripts - Part I
on 07-05-2009 4:36 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetShoutout wrote What is a build script? Writing MsBuild Scripts - Part I - Tuna Toksoz - Devlicio.us
on 07-05-2009 5:14 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Filip wrote re: What is a build script? Writing MsBuild Scripts - Part I
on 07-06-2009 5:36 PM

It would be interesting to see how MSBuild can be used for building C++ projects. How would it handle dependencies on included header files?

Tuna Toksoz wrote re: What is a build script? Writing MsBuild Scripts - Part I
on 07-06-2009 5:47 PM

For reference, I found this one

www.developer.com/.../3800011

I don't have a real experience with c++ projects on a build system, so i don't have real answer.

Thedric Walker wrote re: What is a build script? Writing MsBuild Scripts - Part I
on 07-07-2009 7:21 PM

Good start. I've always been curious about those crazy build files.

BTW there is a new build script tool called Fake. It uses F# to write the script.  You can check it out at http://code.google.com/p/fake/

Tuna Toksoz wrote re: What is a build script? Writing MsBuild Scripts - Part I
on 07-07-2009 7:27 PM

@Thedric

Thank you. Yes, after the post, I have seen Fake and also remembered Boobs(Boo Building System).

All those have their pros and cons, and sometimes it comes down to personal taste :)

Jan Moseneke wrote re: What is a build script? Writing MsBuild Scripts - Part I
on 08-25-2009 8:04 AM

what is build script and whats the importance of using it

Amogelang Mathe wrote re: What is a build script? Writing MsBuild Scripts - Part I
on 08-28-2009 3:31 AM

Significance of using build script

devlicio.us/.../item-note.png

Sharon Makgoshing wrote re: What is a build script? Writing MsBuild Scripts - Part I
on 08-28-2009 3:33 AM

What is the main purpose of building script?

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)