-Brief overview
Nant ? Nant comes from the makers on Ant which is one of the build provider of Java. The current version of Nant (0.86) has been in beta since December of 2007. Nant is an XML based build tool.
MsBuild- MsBuild is Microsoft's build tool and is built into Visual Studio. Visual Studio 2005 and 2008 project files are in fact MsBuild files and can be used to build your project (solution files are not MsBuild files but can be used with MsBuild as they point to all of the necessary projects and indicate in what order they need to be built). MsBuild is also an XML based build tool.
Which one should I use?
Well the answer is it depends?. Nant has been around much longer and supports Visual Studio 2003 and 2005 project formats as well as .Net v1.1. Since Nant has been around a lot longer you are most likely going to find more blog documentation on Nant and if lucky you might find someone on your team that is familiar with Nant.
The problem with Nant is that it is dead in many ways. For starters it has been in beta for about the last year and half. I tried using the beta and received multiple errors when I tried to run the beta on a Windows Server 2003 x64 machine. I ended up having to download a nightly build to get Nant to work on a 64 bit machine. Nant does not recognize Visual Studio 2008 project files so if you are using the latest version of Visual Studio then you will need to build your project by executing a command line call to?. yup you guessed it MsBuild.
MsBuild is a little bit newer on the scene and does not suffer from the Beta issues that you will find with Nant (it runs on anything .Net runs on). One of the largest advantages to using MsBuild is that it builds your project/solution in the same way that Visual Studio does. One of MsBuild?s noted shortcomings are the lack of features that it provides( an example would be SVN checkout ). This however can easily be overcome with the help of the MsBuild Community Project.
The New Comer has Momentum
If you are working with .Net 1.1 apps and using Visual Studio 2003 you are most likely going to want to stick with Nant as MsBuild does not support .Net 1.1 (though there is a toolkit on Codeplex which gives .Net 1.1 support to MsBuild found here). If you are targeting .Net 2+ using or switching to MsBuild is probably the way to go as all the major .Net IDEs support MsBuild. Sharpdevelop fully supports MsBuild 3.5 and as of version 2.0 MonoDevelop is now using MsBuild as its default project format and in the next version of Mono will be releasing a first gen MsBuild equivalent for Mono so that you can build your project in the same way.
Where is the code?
I am not a big fan of code articles without code so here is a basic MsBuild example to help you get started. As a bonus I have shown how to use Gallio to execute test cases as Gallio can run NUnit, XUnit, MbUnit, CsUnit and MsTest.
<Project DefaultTargets="RunTests"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import
Project="C:\Tools\MSBuild.Community.Tasks.v1.2.0.306\Build\MSBuild.Community.Tasks.Targets"/>
<UsingTask AssemblyFile="C:\Tools\Gallio3.06\bin\Gallio.MSBuildTasks.dll"
TaskName="Gallio" />
<ItemGroup>
<TestAssemblies
Include="$(MSBuildProjectDirectory)\MyProject\bin\Debug\MyProject.Test.dll" />
</ItemGroup>
<Target Name="Compile">
<!-- Rebuild entire solution -->
<MSBuild Projects="MyProject.sln" />
<Delete Files="$(MSBuildProjectDirectory)\Publish\bin\System.Data.SQLite.dll"
ContinueOnError="true" />
<Delete Files="$(MSBuildProjectDirectory)\Publish\bin\System.Data.SQLite.xml"
ContinueOnError="true" />
</Target>
<Target Name="RunTests" DependsOnTargets="Compile">
<Gallio IgnoreFailures="true" Assemblies="@(TestAssemblies)"
ReportDirectory="$(CCNetLastBuildFolder)"
reportNameFormat="Test_XML_NAME"
ReportTypes="Xml" >
<!-- This tells MSBuild to store the output value of the task's
ExitCode property into the project's ExitCode property -->
<Output TaskParameter="ExitCode" PropertyName="ExitCode"/>
</Gallio>
<Error Text="Tests execution failed" Condition="'$(ExitCode)' != 0" />
</Target>
</Project>
-