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”.


MSBuild Community Tasks Project releases version v1.0.0.29

Announcement

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

Current Community Tasks

TaskDescription
AssemblyInfoGenerates an AssemblyInfo file using the attributes given.
FtpUploadUploads a file using File Transfer Protocol (FTP).
MailSends an email message.
Math.AddAdd numbers.
Math.DivideDivide numbers.
Math.MultipleMultiple numbers.
Math.SubtractSubtract numbers.
NDocRuns NDoc V1.3.1 to create documentation.
NUnitRuns tests using the NUnit V2.2 framework.
RegistryReadReads a value from the Registry.
RegistryWriteWrites a value to the Registry.
SvnCheckoutCheckout files from Subversion
SvnClientSubversion Client
SvnCommitCommit files to Subversion
SvnExportExport files from Subversion
SvnUpdateUpdate files from Subversion
SvnVersionGet Subversion revision number of a local copy
UnzipUnzip a file to a target directory.
VersionIncrements a four-part version number stored in a text file
XmlReadReads a value from a XML document using a XPath.
XmlWriteUpdates a XML document using a XPath.
ZipCreate a zip file with the files specified.

Join Project

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


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 http://msbuildtasks.com/ which is a community server install with forums and a directory of MSBuild tasks. The goal of msbuildtasks.com is to provide a common place to find tasks. Please help improve this directory by adding links to tasks that you know about.


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  
{  
    [TestClass]  
    public class GenericTest  
    {  
        [TestMethod]  
        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);  
            watch.Stop();  
  
            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>();  
            watch.Stop();  
  
            Console.WriteLine("Normal Create Time: {0} ms", watch.Elapsed.TotalMilliseconds);  
        }  
  
        public Collection<T> GetCollection<T>()  
        {   
            return new Collection<T>();   
        }  
  
        [TestMethod()]  
        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);  
            watch.Stop();  
  
            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>();  
            watch.Stop();  
  
            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 https://www.google.com/tbproxy/spell?lang=en&hl=en.

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>
</spellrequest>

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>
</spellresult>
TagDescription
oThe offset from the start of the text of the word
lLength of misspelled word
sConfidence of the suggestion
textTab delimited list of suggestions

I created a complete C# GoogleSpell library as a demo. The library can be download at http://www.loresoft.com/files/uploads/GoogleSpell.zip