Building an application can be more than pressing F5. Much more. With an increasing number of quality packages being released, developers for the .NET platform now have options to create a very sophisticated build process. This article describes a sample build environment and shows how a number of tools can work together to make reliable, predictable, and value added builds.

The goals of the build system are outlined below.

  • Monitor source control for changes
  • Get latest source code from source control
  • Build the application in a versioned directory
  • Run unit tests over the new assemblies
  • Validate coding standards on the new assemblies
  • Create documentation based on the latest code
  • Publish the results to the Web and via e-mail

As you can see, the build process will automate many tasks.

First you will start with NAnt and create a sample build. Then you will expand the NAnt build file to run some other tasks as a sample of what else can be done. The steps are listed below.

  • Setup the build environment
  • Build a "program" solution with Visual Studio .NET
  • Create first NAnt build file and build
  • Build a "test" project with Visual Studio .NET
  • Add NUnit tests to build
  • Validate coding standards during build with FxCop
  • Create API Documentation during build with NDoc
  • Add the solution to VSS source control
  • Add SCC control to the build file
  • Add versioning
  • Use CruiseControl.NET to monitor and manage the build process
    • Trigger a build once something has changed
    • Report back to build master outcome via email and Web reporting

This article is not an in-depth introduction to any of the concepts or tools used. This article should serve as a technical example of how some of the available tools can be used together. This is also just an example. All of the tools used here have many options that will not even be touch upon. You are encouraged to look deep into the help for each of these products and become creative in your own build process.

Overview

The main purpose of a build process is to build an application. A build process should collect all of the pieces of an application and create a deployable package for this specific version. By making this a process of its own, you add both reliability and predictability.

Beyond a predictable build, a number of tools have been introduced that allow for other automated tasks to be run. In a team development environment, the build process would typically bring together code from a number of developers. That makes build time the ideal place to run tasks such as unit tests, and documentation creation. Having these tasks automated in the build can increase the quality of your code and offload some important tasks from the developers.

In addition to adding value to builds, you also have the facility to track and report on the builds. When configured to trigger on a check into source control, your development team can receive unit test results via e-mail within minutes of any given change. This allows developers to react quickly to changes while they are still thinking about the change.

The reporting also includes the results of a check against the coding standards. This allows code reviews to focus on code instead of standards.

Below is a list of the packages that will be used, a brief description of each package and how it will be utilized.

Nant (http://nant.sourceforge.net/)
NAnt is the platform that will be used to create the actual build process. NAnt is an open source package modeled after Ant for Java. NAnt will be responsible for the actual building, as well as triggering any other tasks that will be run throughout the build process.

NAntContrib (http://nantcontrib.sourceforge.net/)
NAntContrib is a collection of add-on tasks for NAnt. NAntContrib is also an open source package. NAntContrib adds tasks for vss, the gac, ngen, and many nice tasks. NAntContrib will be used to communicate with VSS.

NUnit (http://www.nunit.org/)
NUnit is an open source unit testing framework for .NET and is modeled after JUnit for Java. NUnit allows developers to create test fixtures and write unit tests for their applications. NUnit includes a GUI and a commandline tool, as well as a set of attributes you add to test assemblies. NUnit will be used to unit test the class library in this article.

NDoc (http://ndoc.sourceforge.net/wiki)
NDoc is an open source package that creates API documentation from XML documentation files from Visual Studio .NET or packages like VBCommentor. NDoc allows developers many options when creating documentation and also comes in GUI and command line flavors. NDoc will be used to create HTML and chm documentation of the application.

CruiseControl.NET (http://ccnet.thoughtworks.com)
CruiseControl.NET ("CCNet") is an open source package used for Continuous Integration and build process reporting. Continuous Integration is a practice of creating a new build once updated files have become available, thus creating a continuous build process. Assuming tasks like unit testing are included in the build process, this allows teams to identify and fix bugs very quickly, provided there is good coverage in the unit tests of course. CCNet will be used to trigger and report on the build process.

FxCop (http://www.gotdotnet.com/team/fxcop/)
FxCop is a package distributed by Microsoft to enforce coding standards. FxCop automates the process of analyzing code for coding standards. This allows peer review sessions to really focus on code and not waste time on things like correcting casing or naming violations. FxCop will be used to analyze the coding standards in the application.

Visual Source Safe (http://www.microsoft.com/vstudio)
Visual Source Safe ("vss") is a source control package distributed by Microsoft. VSS is commonly used for source control when using Visual Studio .NET. It's used here because of its wide availability and adoption, but the concepts in this article would translate to most other source control systems by changing a couple elements in the NAnt file.

Setup Build Environment

[Easy Way Unzip attached BuildSolution.zip into c:\projects Unzip attached devtools.zip into c:\devtools] So now it's time to dive right into action. The first thing that needs to be done is to install these tools. Although not necessary, it's nice to have these tools in one place, i.e. c:\DevTools.

Provided with this article is a devtools.zip of the various packages that should be installed here and configured appropriately. You can extract this zip file into c:\devtools to review the samples. The steps are outlined below.

Install/Extract Packages

  1. Download and extract NAnt to c:\devtools
  2. Download and extract NantContrib to c:\devtools
  3. Download and install nunit to c:\devtools
  4. Download and install NDoc to c:\devtools
  5. Download and install FxCop to c:\devtools
  6. Download and extract CCNet to c:\devtools

Add NAntContrib to Nant

  1. Copy all of the files from c:\devtools\nantcontrib\bin into c:\devtools\nant\bin

[Read More]