Having just spent a frustrating amount of time configuring an automated build with psake the thought occurred to me why not use the language I know best to create a builder?
psake is an excellent framework to create an automated build. The trouble I always have is learning powershell to run more complex tasks. I'm sure the same can be said for NAnt, msbuild, etc.
My idea to solve this problem is create the build system for a given solution in .Net. The basic structure of the process would be this:
build.bat
rem // Set the environment for msbuild.
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
rem // Build the solution's builder.
msbuild.exe buildsolution.csproj
rem // Run the solution's builder.
BuildSolution.exe <task>
Project's BuildSolution
A tiny console application that:
- References the BuildSolution framework.
- Includes a method for each task. eg:
- Clean
- Build
- Test
- Commit
- Registers the tasks, and their dependencies, it can run. eg:
- Builder.RegisterTask( x => x.Clean )
- Builder.RegisterTask( x => x.Build ).DependsOn( x => x.Clean )
- Builder.RegisterTask( x => x.Test ).DependsOn( x => x.Build )
- Builder.RegisterTask( x => x.Commit ).DependsOn( x => x.Test )
- Runs the builder. eg Builder.Execute()
Test Task
Ultimately the test task will call nunit, mstest, xunit, etc but first builds the required command line. This is an example of where using .Net instead of PowerShell is a winner for me.
When I develop my applications I follow a simple naming convention of ProjectName and ProjectName.Tests. The build system searches for *.Tests.dll and includes them in the mstest command line.
The advantages of using a .Net application to construct this task is:
- No need to learn a scripting language to find test dlls.
- Develop with an IDE I know well and is feature rich.
- Debug the task with an IDE I know well and is feature rich.
Summary
In addition to the advantages listed in Test Task the BuildSolution idea has the advantage that it is arguably easy for new developers to the project to understand and edit the build system.
What cons do you see for the idea of BuildSolution?