concept MSBuild in category software development

appears as: MSBuild, MSBuild
Agile ALM: Lightweight tools and Agile strategies

This is an excerpt from Manning's book Agile ALM: Lightweight tools and Agile strategies.

7.2.1. Using MSBuild to build .NET projects

MSBuild provides a series of targets, each of which defines one or more tasks to be carried out. Targets are a sequence of grouped steps; this is similar to Ant, where targets are a sequence of Ant tasks. The following listing shows a sample build script.

Listing 7.4. A simple build script for .NET with MSBuild

As you can see, there’s support for concepts such as multiple targets (that is, one script being able to run different tasks and operations), property definitions, and conditions. Like NAnt, MSBuild is also extensible. You can create new tasks by implementing an interface and referencing it as an external assembly.[4]

Continuous Integration in .NET

This is an excerpt from Manning's book Continuous Integration in .NET.

Next, you need something to do the actual build. The two most common options are MSBuild and NAnt. MSBuild is part of the .NET Framework, so it’s free and most closely matches what happens when you click Build from the Visual Studio menu. NAnt is designed after the Java tool Ant. It’s an open source solution, but it has received few updates in the past couple of years. Both applications are controlled by XML configuration files, but you can find GUI tools such as MSBuild Sidekick (see figure 1.5) to make the configuration files easier to maintain.

Figure 1.5. MSBuild Sidekick from Attrice makes it easy to develop and maintain MSBuild scripts.

The build-manager application takes a Visual Studio solution or individual project files and calls the correct compiler, generally C# or VB.NET. The compilers come free as part of the .NET Framework. Some shops use MSBuild for the actual compilation of the source and then use NAnt for the remaining steps, such as running unit tests.

All the tools we’ve mentioned can be used to set up a CI process. But we’ll look at the vanguard of build automation: the XML-based build systems Ant (NAnt) and MSBuild. The XML-based systems are a step away from tools that use fairly complicated commands or a programming language to describe the build process. Using them, you can declare the steps in an XML build script, and the steps are easy to extend and adapt.

NAnt and MSBuild are two of the tools you should choose from if you’re creating a build process in a .NET environment. Both do the same job using similar techniques. NAnt is an open source tool maintained by the community, and MSBuild comes from Microsoft. Table 3.1 shows the most significant differences between them.

Table 3.1. NAnt vs. MSBuild: significant differences

Feature

NAnt

MSBuild

Actively developed no yes
Built-in features yes some
Open source yes no
Cross-platform (Linux, Mono) yes no
Good if you already know Ant yes no
Built in to .NET Framework yes yes
Integrated with Visual Studio no yes

Let’s take a quick look at NAnt and see why we’ll go with MSBuild instead.

3.2.1. First encounters with MSBuild

To use MSBuild from the command line, you have to write the full path for the executable or add it to your System Paths variable. But if you have Visual Studio installed, you can use the Visual Studio Command Prompt, which knows the path to MSBuild. You launch the Visual Studio Command Prompt from the Windows Start menu (see figure 3.2).

Figure 3.2. The Visual Studio Command Prompt knows the paths to various handy .NET tools. One of them is MSBuild.

As a small workout in MSBuild, you’ll perform the same tasks as you did previously with NAnt. Write another captivating one-liner:

If the path to MSBuild exists in system variables or you’re using the Visual Studio Command Prompt, the only thing you have to do is start MSBuild from the command line. Type msbuild to launch and run the build process (see figure 3.3).

Figure 3.3. MSBuild is less verbose than NAnt. If you have only one file with the *.proj extension in the directory where you start MSBuild, it’s automatically executed.
<Target Name="Build" >
<MSBuild Targets="Clean;Rebuild"
Projects="CiDotNet.sln"
ContinueOnError="false"
Properties="MSBuildExtensionsPath32=..\tools" />
</Target>
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage