Sample build file using MSBuild Community Tasks

The MSBuild Community Tasks Project has released the first version of tasks. The following is a sample build project that uses the SvnVersion, AssemblyInfo, NDoc and Zip tasks to create a release.

Import Targets

The first thing that needs to be done in the build file is to import the MSBuild.Community.Tasks.Targets file that defines the available tasks. If you use the msi installer to install the MSBuild Community Tasks, you can use the path “$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets”.

Version Target

The first target in the sample file is the Version target. The version target is used to update the latest version number. First the SvnVersion task is used to get the latest Revision number from the local working subversion repository. SvnVersion outputs the Revision to the Revision property.

Next the target uses the AssemblyInfo task to generate an AssemblyInfo.cs file with the attributes specified.

Compile Target

The compile target calls msbuild to compile the solution in release mode. The MSBuild target will compile the solution the exact same way Visual Studio will.

Documentation Target

To create help for the project, there is the documentation target. In the documentation target, the NDoc task is used to compile a HTML Help project. To use the NDoc task, you must have NDoc 1.3.1 installed.

The generated HTML Help file is then moved to the documentation folder and the temp files are cleaned up.

Zip Target

The zip target is used to package up the whole project into a zip file. Zip target uses the Zip task to create the zip. The files included in the zip are selected by the ItemGroup ZipFiles.

Sample Master.proj File

<?xml version="1.0" encoding="utf-8"?>  
<Project DefaultTargets="Build" xmlns="">  
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>  
    <DefaultExclude Include="**\.svn\**" />  
    <DefaultExclude Include="**\bin\**" />  
    <DefaultExclude Include="**\obj\**" />  
    <DefaultExclude Include="**\Release\**" />  
    <DefaultExclude Include="**\Debug\**" />  
    <DefaultExclude Include="**\Test\**" />  
    <DefaultExclude Include="**\TestResults\**" />  
    <DefaultExclude Include="**\doc\**" />  
    <DefaultExclude Include="**\www\**" />  
    <DefaultExclude Include="**\*.user" />  
    <DefaultExclude Include="**\*.suo" />  
    <DefaultExclude Include="**\*.zip" />  
    <DefaultExclude Include="**\*.txt" />  
    <ZipFiles Include="**\*.*" Exclude="@(DefaultExclude)" />  
  <Target Name="Version">  
    <SvnVersion LocalPath="$(MSBuildProjectDirectory)">  
      <Output TaskParameter="Revision" PropertyName="Revision" />  
    <Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/>  
    <AssemblyInfo CodeLanguage="CS"   
      AssemblyTitle="MSBuild Community Tasks"  
      AssemblyDescription="Collection MSBuild Tasks"  
      AssemblyCopyright="Copyright © Paul Welter 2005"       
      Condition="$(Revision) != '0' "/>  
  <Target Name="Compile" DependsOnTargets="Version">  
    <MSBuild Projects="Source\MSBuild.Community.Tasks.sln"  
             Properties="Configuration=Release" />  
  <Target Name="Documentation" DependsOnTargets="Compile">  
    <NDoc Documenter="MSDN"  
          ProjectFilePath="Documentation\MSBuild.Community.Tasks.ndoc" />  
    <Copy SourceFiles="doc\MSBuild Community Tasks.chm"  
          DestinationFiles="Documentation\MSBuild.Community.Tasks.chm" />  
    <RemoveDir Directories="doc" />  
  <Target Name="Zip" DependsOnTargets="Documentation">  
    <Zip Files="@(ZipFiles)"  
         ZipFileName="MSBuild.Community.Tasks.v$(Major).$(Minor).$(Build).$(Revision).zip" />  
  <Target Name="Build" DependsOnTargets="Zip">  
    <Message Text="CodeSmith Build Complete"/>  

I hope this sample will help in creating build files for your project.

~ Paul

MSBuild Community Tasks Project releases version v1.0.0.29


The MSBuild Community Tasks Project releases version v1.0.0.29. The following is a list of tasks.

Current Community Tasks

Task Description
AssemblyInfo Generates an AssemblyInfo file using the attributes given.
FtpUpload Uploads a file using File Transfer Protocol (FTP).
Mail Sends an email message.
Math.Add Add numbers.
Math.Divide Divide numbers.
Math.Multiple Multiple numbers.
Math.Subtract Subtract numbers.
NDoc Runs NDoc V1.3.1 to create documentation.
NUnit Runs tests using the NUnit V2.2 framework.
RegistryRead Reads a value from the Registry.
RegistryWrite Writes a value to the Registry.
SvnCheckout Checkout files from Subversion
SvnClient Subversion Client
SvnCommit Commit files to Subversion
SvnExport Export files from Subversion
SvnUpdate Update files from Subversion
SvnVersion Get Subversion revision number of a local copy
Unzip Unzip a file to a target directory.
Version Increments a four-part version number stored in a text file
XmlRead Reads a value from a XML document using a XPath.
XmlWrite Updates a XML document using a XPath.
Zip Create a zip file with the files specified.

Join Project

Please join the MSBuild Community Tasks Project and help contribute in building the tasks.

Get The Source

You can get a local copy of the repository for MSBuild Community Tasks via Subversion. The following command will do the trick:

svn checkout

Download The Latest

The latest binaries, source and installer for Windows can be found in this directory of the Tigris file-sharing area.

MSBuild Community Task Collaboration Project

I’d like to announce the MSBuild Community Task Collaboration Project. The project was started by me to form a directory of MSBuild Tasks for use in your build scripts. The project is also an open source collection of tasks. The project is broke into 2 web sites.

The first is which is a community server install with forums and a directory of MSBuild tasks. The goal of is to provide a common place to find tasks. Please help improve this directory by adding links to tasks that you know about.

The second site is an open source project hosted at The goal of this site is to build a collection of tasks that is open source for the community. Please create an account on and join the project to help build out the tasks.

Thanks for contributing to the MSBuild community.

~ Paul

Generics at Runtime

Here is a little test code that demonstrates how to use Generics at runtime. The code has two tests. The first test shows how to create a Generic Class at runtime. The second shows how to call a Generic method. Keep in mind that when using generics at runtime, there will be a reflection performance hit.

using System;  
using System.Collections.ObjectModel;  
using Microsoft.VisualStudio.QualityTools.UnitTesting.Framework;  
using System.Reflection;  
using System.Diagnostics;  
namespace GenericTest  
    public class GenericTest  
        public void CreateGenericAtRuntime()  
            Stopwatch watch = Stopwatch.StartNew();  
            // define the generic class at runtime  
            Type genericType = typeof(Collection<>).MakeGenericType(typeof(DateTime));  
            // create an instance of the generic type  
            object instance = Activator.CreateInstance(genericType);  
            Console.WriteLine("Dynamic Create Time: {0} ms", watch.Elapsed.TotalMilliseconds);  
            Assert.IsNotNull(instance, "instance is Null");  
            Assert.IsTrue(instance is Collection<DateTime>);  
            Collection<DateTime> dates = instance as Collection<DateTime>;  
            Assert.IsNotNull(dates, "dates is Null");  
            watch = Stopwatch.StartNew();  
            Collection<DateTime> d = new Collection<DateTime>();  
            Console.WriteLine("Normal Create Time: {0} ms", watch.Elapsed.TotalMilliseconds);  
        public Collection<T> GetCollection<T>()  
            return new Collection<T>();   
        public void CallGenericMethodAtRuntime()  
            Stopwatch watch = Stopwatch.StartNew();  
            MethodInfo methodInfo = typeof(GenericTest).GetMethod("GetCollection");  
            MethodInfo genericInfo = methodInfo.MakeGenericMethod(typeof(DateTime));  
            object instance = genericInfo.Invoke(this, null);  
            Console.WriteLine("Dynamic Invoke Time: {0} ms", watch.Elapsed.TotalMilliseconds);  
            Assert.IsNotNull(instance, "instance is Null");  
            Assert.IsTrue(instance is Collection<DateTime>);  
            Collection<DateTime> dates = instance as Collection<DateTime>;  
            Assert.IsNotNull(dates, "dates is Null");  
            watch = Stopwatch.StartNew();  
            Collection<DateTime> d = this.GetCollection<DateTime>();  
            Console.WriteLine("Normal Invoke Time: {0} ms", watch.Elapsed.TotalMilliseconds);  

Google Toolbar Spell Check API

I saw in this post that the Google toolbar could be extracted and looked at. So, I spend an afternoon reverse engineering the spell checker api. The api ends up to be very easy to use. Checking is done with an HTTP post to

The xml structure looks like this…

<?xml version="1.0" encoding="utf-8" ?>  
<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">  
    <text>Ths is a tst</text>  

The response look like …

<?xml version="1.0" encoding="UTF-8"?>  
<spellresult error="0" clipped="0" charschecked="12">  
    <c o="0" l="3" s="1">This Th's Thus Th HS</c>  
    <c o="9" l="3" s="1">test tat ST St st</c>  
Tag Description
o The offset from the start of the text of the word
l Length of misspelled word
s Confidence of the suggestion
text Tab delimited list of suggestions

I created a complete C# GoogleSpell library as a demo. The library can be download at

Here is an example on how to use GoogleSpell …

string text = "ths is a tst";  
SpellRequest request = new SpellRequest(text);  
SpellResult result = SpellCheck.Check(request);  
foreach (SpellCorrection correction in result.Corrections)  
    Console.WriteLine("Misspelled: {0} ({1}:{2})",   
        text.Substring(correction.Offset, correction.Length),   
        correction.Offset, correction.Length);  
    foreach(string suggestion in correction.Suggestions)  
        Console.WriteLine("    {0}", suggestion);  

I plan to develop an ajax web client for the google spell api. This will be really sweet as it won’t require anything to be installed on the sever other then a js file. I’ll post again when I have the web client complete.