Setting up a the build file for a new application

Tuesday, 04 December 2007

Posted by Sébastien Lachance with Comments (0)

(Index of the whole series)

This is really easy on a new project! I think that the success on setting up a build file is going a step at a time. Unfortunately this is not always the case in some of our projects due to time constraints.

I am using NAnt for this.

Step 1. Deciding where I wanted to put my build.

Going with some advices I decided to go on the classic build folder. I make sure the folder is deleted and created back at every build.

 

 

<!-- Start by cleaning the build area -->
<target name="clean">
  <delete dir="build" if="${directory::exists('build')}" />
</target>

<!-- Create a build area -->
<target name="init">
  <mkdir dir="build"/>
</target>

Step 2. Compiling the project.

This is where the challenge lies. The csc Nant task is not aware of the .NET 3.5 framework. To get around this problem I have download a nightly build of NAnt 0.86. Works perfectly, until... Remember I'm using WPF for my GUI. I was getting some strange errors about something missing in the System.Window. Full error :

      [csc] Compiling 7 files to 'C:\dev\LogItAll\build\LogItAll.exe'.
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\App.xaml.cs(13,32): error CS0246: The type or namespace name 'Application' could not be found (are you missing a using directive or an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(6,22): error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(7,22): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(8,22): error CS0234: The type or namespace name 'Documents' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(9,22): error CS0234: The type or namespace name 'Input' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(10,22): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(11,22): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(12,22): error CS0234: The type or namespace name 'Navigation' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(13,22): error CS0234: The type or namespace name 'Shapes' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(20,36): error CS0246: The type or namespace name 'Window' could not be found (are you missing ausing directive or an assembly reference?)

Humm, why is there something so obvious that it should be there failing? The reason is that some of the libraries required on a WPF project are not in the GAC. They are located in the C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\. Next, there is the problem that some file are generated and not always there, the InitializeComponent method is missing everywhere.... This is strange, how can I use csc.exe to generate those files? You can't use csc.exe, when you use XAML ! After a lot of googling, I stumbled upon this MSDN page. I had no choice but start using MSBuild for the compilation.

So I changed my csc task to an exec task and called MSBuild. I was now facing the problem that the assembly are compiled and put in their respective folder. A little change to the Output path in Visual Studio 2008 did the trick. Note that I am not using it on all project. I'm only interested in the UI project and all the tests projects. They are all what I need to run the application and the unit test.

outputpath

This is what the NAnt section look like:

 

 

<target name="compile" depends="init">
    <exec
    program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe"
    commandline="LogItAll.sln"/>
</target>
3. Executing the tests.

 

 

<target name="test" depends="compile">
  <exec basedir="tools\mbunit\"
    useruntimeengine="true"
    workingdir="build"
    program="mbunit.cons.exe"
    commandline="LogItAll.Domain.Tests.dll /rt:html /rf:"."" />
</target>
I'm still trying to find a more generic way to execute all the test projects. As you can see I am using MBUnit as my unit testing tool for this application.
4. Result

 

 

<?xml version="1.0"?>
<project name="LogItAll" default="all">

  <target name="all"/>

  <!-- Start by cleaning the build area -->
  <target name="clean" description="remove all build products">
    <delete dir="build" if="${directory::exists('build')}" />
  </target>

  <!-- Create a build area -->
  <target name="init" depends="clean">
    <mkdir dir="build"/>
  </target>

  <target name="compile" depends="init">
      <exec
      program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe"
      commandline="LogItAll.sln"/>
  </target>

  <target name="test" depends="compile">
    <exec basedir="tools\mbunit\"
      useruntimeengine="true"
      workingdir="build"
      program="mbunit.cons.exe"
      commandline="LogItAll.Domain.Tests.dll /rt:html /rf:"."" />
  </target>

</project>



blog comments powered by Disqus