Many people seem to be afraid of the angled brackets that accompany MSBuild and tend to avoid it. This is a pity as MSBuild can be as simple or complex as you want to make it. The beauty of the tool is that it’s kinda like Lego; you build it bit by bit, enhance it, break it, build it better.
I thought in Part 1 of this series I’d keep it as simple as possible and show how to compile a solution using MSBuild. We’ll need a starting point, so I’ve attached a sample application that will be used throughout. Note, this sample application uses the Microsoft Solutions Build Framework (v2.0.060717.001) from GotDotNet. You can download this now and take a look, or you can follow this series and see how we take a basic solution compiling to something a little more useful. The SBF provides a bunch of MSBuild tasks, so we don’t need to write them ourselves!
- Download and unzip the attached file to your PC
- Open a .NET 2.0 command prompt to the path of the Build.Proj file
- Run MSBuild.exe Build.proj
You should see a successful build of your solution (assuming it compiles ok).
That’s all there is to it. Add the build folder to each of your solutions, then a few lines of MSBuild configuration and you can compile your solution. In fact the only part you should need to change in to compile your solution is the orange part below
<?xml version=”1.0″ encoding=”utf-8″?>
<Project DefaultTargets=”Full” xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″>
<!–IMPORT THE MS SBF TARGETS–>
<!– BUILD THE MAIN SOLUTION.–>
<Tools.DevEnv VisualStudio=”8.0″ Path=”$(MSBuildProjectDirectory)\..\SampleConsoleApp\SampleConsoleApp.sln” Config=”Release” Clean=”true”/>
Great! But we need more. What about SourceSafe / TFS integration. What about notifications. What about deployment. What about labeling. What about FXCop integration….
All this is to come, but first get yourself accustomed to the simple sample in part 1.