I spent some time with MSBuild this week... I actually like it (yea that's right, i said it!), but it did take me some time to figure out how to write a basic build script from scratch that can be used to build a solution and run the tests. Obviously, i wanted the script to assume as little as possible, so i could pretty much drop it any solution folder and use it as is. The only thing that is hardcoded is the path the nunit console runner but other than that, this should provide a good start for pretty much any project.
<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<PropertyGroup>
<Configuration>Debug</Configuration>
<NUnitRunner>C:\Program Files\NUnit 2.4.7\bin\nunit-console.exe</NUnitRunner>
</PropertyGroup>
<ItemGroup>
<ProjectsToBuild Include="**\*.csproj" />
</ItemGroup>
<Target Name="BuildAll" DependsOnTargets="Clean;CoreBuild;RunTests"/>
<Target Name="CoreBuild">
<MSBuild Projects="@(ProjectsToBuild)" ContinueOnError="false" Properties="Configuration=$(Configuration)">
<Output ItemName="BuildOutput" TaskParameter="TargetOutputs"/>
</MSBuild>
</Target>
<Target Name="Clean">
<MSBuild Projects="@(ProjectsToBuild)" ContinueOnError="false" Targets="Clean"
Properties="Configuration=$(Configuration)" />
</Target>
<Target Name="RunTests" DependsOnTargets="CoreBuild">
<CreateItem Include="**\Bin\Debug\*Tests*.dll" >
<Output TaskParameter="Include" ItemName="TestAssemblies" />
</CreateItem>
<NUnit ToolPath="$(NUnitPath)" Assemblies="@(TestAssemblies)" DisableShadowCopy="true" />
</Target>
</Project>
it uses the MSBuild Community tasks btw... Like i said, this is a very basic script. It only builds your solution and it runs all of your tests. That's it. No packaging of the output, no code coverage (if you're really doing TDD, code coverage is useless anyway), no whatever else you can think of. But you can easily add all of that stuff of course ![]()
Now watch me get flamed for not using nant ![]()
Pingback: The Inquisitive Coder - Davy Brion’s Blog » Blog Archive » The CI Build should be a given