I’m starting a series on build automation using msbuild. This will cover topics including the basics of msbuild, advanced topics using extensions, custom tasks and using msbuild as a deployment tool.
Well, the simple answer. Its already there, its a build system maintained by Microsoft and keeps up to date with the latest version of .net.
Like with everything else, for a robust build system to work, it takes some planning.
- Project layout – this will allow us to traverse the directory structure.
- Build requirements – Do we want to build in Debug/release both?? Do we want to run tests??
- Naming convention – come up with a meaningful naming convention.
Ok, so the basics of msbuild. MSBuild is a Microsoft build platform shipped with the .net framework. Version 3.5 of MSBuild, which is bundled together with .NET 3.5 (and Visual Studio 2008), allows .NET projects to be built for either 2.0, 3.0 or 3.5 .NET version support (so called “multi-targeting”).
It is possible to build Visual Studio projects and solutions without the Visual Studio IDE installed and MSBuild is available at no cost.
Its based on an XML syntax, so we start with ..
<?xml version=”1.0″ encoding=”utf-8″?> next we add in the project tag. This encloses all the targets, properties and items required for the build. In adition to the namespace declaration, there’s 3 additional attributes worth noting. InitialTargets, ToolsVersion and DefaultTargets.
Xmlns : Required attribute.The xmlns attribute must have the value of “http://schemas.microsoft.com/developer/msbuild/2003″.
ToolsVersion: sets a target .NET Framework version to build the project with.Optional attribute
DefaultTargets: the default target(s) to run. Optional attribute. If no default target is specified in either the DefaultTargets attribute or the MSBuild command line, the engine executes the first target in the project file after the Import elements have been evaluated.
InitialTargets:runs before the targets specified in the DefaultTargets Optional attribute
<Project xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″ InitialTargets=”runs_before_the_default”
When specifying targets you can seperate multiple targets using a semicolon. The project file contains Property Groups, Item Groups and Targets. Targets contain a collection of executable tasks.
In the next post we’ll put all this together on a typical project.