Basic MSBuild script
Posted by Davy Brion on July 4th, 2008
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
July 4th, 2008 at 10:09 pm
shtt… be very silent about your likings or you’ll become an mvp or .. a regional director !
July 17th, 2008 at 6:38 am
Very good Script for starters. Helped me a lot. Thank you.
August 19th, 2008 at 10:24 pm
[...] what does it take then? Drop in a simple, standard build script which builds your project and runs the tests, add a build configuration and you’re done. [...]
January 11th, 2010 at 3:21 pm
Where is DefaultTargets=”Build”. The target does not exist in your script. Should that have been Buildall
January 11th, 2010 at 5:06 pm
@Zak
indeed it should have been
January 11th, 2010 at 10:22 pm
@Davy : Thanks. I thought I missed something.