Previously, I have spoke about how you can update your AssemblyInfo file using MSBuild. However, I haven’t spoken about the very basics – how to build a Visual Studio solution and execute your unit tests.
MSBuild is a very interesting build scripting language, out of the box it includes a set of standard tasks which you can use based on your requirements, such as creating a directory or copying a file in order to correctly build your project. I also take advantage of the MSBuild community task project, while it hasn’t been updated in a while, the tasks work perfectly.
Below is the basic MSBuild script.
<MSBuild Projects=”TeamCityBlogExample.sln” Properties=”Configuration=Release” />
<NUnit Assemblies=”TeamCityBlogExample.TestsbinReleaseTeamCityBlogExample.Tests.dll”
ContinueOnError=”false”
ToolPath=”C:Program FilesTestDriven.NET 2.0NUnit2.4″
OutputXmlFile=”NUnitResults.xml” />
Within the project section at the top, I set the default target to Test. This is the target which will be executed first, the Test target then has a DependsOnTarget attribute which enforces that the build must be done before we test.
On line 3, I import a reference to the MSBuild community tasks so I can access all of the custom tasks included – such as NUnit. Next I define my build target, within this I define the solution I want to build and the configuration. To execute my unit tests, I use the NUnit task from the community task project, this takes a list of all the assemblies which we need to run, define if a test fails wether it should fail the build and finally tell it where NUnit lives on the local machine.
Now, the script can be executed by a build system, such as CCNet or TeamCity, or from the command line using the msbuild.exe
Download script: http://blog.benhall.me.uk/Code/Build/BaseMSBuildScript.txt
You might find this interesting:
http://code.google.com/p/metabuild/