Far Away Developer

Sebastien Lachance

Archive for December, 2007

Screencast goodness

Posted by Sebastien Lachance on December 24, 2007

Here is the bests screencasts I have watched this week :

Monorail Quickly: A screencast made by Joey Beninghove (joeyDotNet). I have quite enjoyed this one. He has done a template project for quickly starting up a solution for Monorail.

A series of screencasts from colinramsay.co.uk :

A ton of new screencasts about ASP.NET 3.5 Extensions.

And I wish you a merry Christmas!

Posted in .NET, ASP.NET, Fun, Learning, Visual Studio | No Comments »

Adding NCover to CruiseControl.NET

Posted by Sebastien Lachance on December 18, 2007

Let’s not go on too much complicated stuff. This is an easy step-by-step to add a coverage report to your automated builds.

Andrew Stopford’s Weblog

Posted in Agile, Continuous Integration, Tests | No Comments »

Congratulation to me!

Posted by Sebastien Lachance on December 12, 2007

I have just received this! The inscription is :

Thank you for the lasting contribution you made to Microsoft Visual Studio. S. Somasegar

Vs2008

I really like receiving gifts, but I would have preferred a free copy of Visual Studio 2008. :) . Anyway, It’s a nice thank you.

Posted in Blogging, General, Visual Studio | No Comments »

Setting up a basic continuous integration server with CruiseControl.NET

Posted by Sebastien Lachance on December 11, 2007

(Index of the whole series)

Before we go on, you need to now what is “Continuous Integration”. This is a long topic and you should probably read Martin Fowler’s article on Continuous Integration.

Now that we have determined the structure of the project and put the source in the repository, we need to set up the continuous integration server. The tool we will use for that is CruiseControl.NET. The guys behind it have really done a great job. We need first to define “what we want”.

What we want :
  1. Checking for modifications in the source repository.
  2. Get the latest version if modifications are detected.
  3. Build the project.
  4. Run the test suite.
  5. Reporting any successes of failures.

We also want to “fail fast”. This means that at any step, if something is wrong, we won’t go further and report it.

So here is the step by step approach :

1. Downloading and Installing CruiseControl.NET

Download CruiseControl.NET here. I’m using the version 1.3. Then double-click on the executable and follow each step. Normally, I’m leaving everything checked except the help files and examples.

You will be asked if you want to use CC.NET server as a Windows Service. Basically, if you want CC.NET to always run (and in my opinion, it should), my advice is to run it as a service. But some scenario may require that you need to run it only once in while. In that case you only need to execute ccnet.exe to start the server. Next, it ask you if you want to create a virtual directory in IIS for the Web Dashboard. I’m leaving it checked as I want to use CC.NET as a service.

2. Setting a basic project in ccnet.config

Find your ccnet.config (in your ccnetinstallationfolder\server). Every step you want to be executed will be defined here. This require some basic knowledge in xml.

 

 

<!--<ccnetconfig><configurationVersion>1.3</configurationVersion></ccnetconfig>-->
<cruisecontrol>
  <project name="LogItAll">

  </project>
</cruisecontrol>

I’m usually starting with an empty configuration file. The <cruisecontrol> tag is the root and you have one <project> tag per project.

 

 

<cruisecontrol>
    <project name="LogItAll">

        <workingDirectory>c:\dev\logitall</workingDirectory>
        <artifactDirectory>c:\dev\logitall\artifact</artifactDirectory>
        <category>Personal application</category>
        <modificationDelaySeconds>10</modificationDelaySeconds>

        <triggers>
          <intervalTrigger name="continuous" seconds="30"/>
        </triggers>

        <labeller type="defaultlabeller">
          <prefix>0.0.</prefix>
        </labeller>

   </project>
</cruisecontrol>

The <workingDirectory> will serve as the root for all our operations. Instead of specifying the full path, we will use the relative path. Example : \tools\nant\nant.exe instead of C:\dev\LogItAll\tools\nant\nant.exe.

The <artifactDirectory> is where every logs (builds, unit tests) is stored. This tag is not needed.

The <category> is simply in which category you want the project to be. This tag is also not needed.

The <modificationDelaySeconds> is the interval of time in which no modification must be done to the source to continue executing all remaining tasks.

We then have the triggers bloc. This block contains all the reasons that we want to perform a build. I recommend using the documentation of CC.NET to learn more. The <intervalTrigger> is, as the name imply, a trigger that will launch the build process every 30 seconds if any modifications is done to the source.

Finally we have the <labeller> which will give a label to the project. There is a lot of different labelers to use. In my case, I’m going with the default and starting the build number at 0.0.*.

3. Checking if any modifications is done to the source and getting the latest version.

The sourcecontrol tag is need to know if the source have changed. This will also get the latest version of the project.

 

 

<cruisecontrol>
    <project name="LogItAll">

   ...

    <sourcecontrol type="svn">
      <trunkUrl>svn://localhost/repos/LogItAll</trunkUrl>
      <workingDirectory>c:\dev\logitall</workingDirectory>
    </sourcecontrol>

    ...

    </project>
</cruisecontrol>

I can’t go on all the details because each source control has it’s own set of properties and features.

A lot of source control providers are supported (SourceSafe,CVS, etc..).

4. Build the project and run the unit tests suite.

First, we need a <tasks> section. This section should contains all action you want to happen in order. Several tasks are available.

A build file will help tremendously. Since we already have the build process in our own file for development, why shouldn’t we use it to build the application on the CI server. Instead of using an MSBuild task and modifying two files each time we change something in our build process, we should use it. You can use the nant task to run our build file.

 

 

<cruisecontrol>
    <project name="LogItAll">

    ...

    <tasks>
      <nant>
        <executable>tools\nant\nant.exe</executable>
        <buildFile>logitall.build</buildFile>
        <targetList>
          <target>test</target>
        </targetList>
      </nant>
    </tasks>

    ...

    </project>
</cruisecontrol>
5. Integrating the results.

Every log files you want to see in the Web Dashboard need to be merged. To do that you need to add the File Merge Task of the publisher task.

 

 

<cruisecontrol>
    <project name="LogItAll">

    ...

    <publishers>
      <merge>
         <files>
            <file>Logs\*.xml</file>
         </files>
      </merge>
      <xmllogger/>
    </publishers>

    </project>
</cruisecontrol>

This will embed the content of all the xml files in the logs folder in an xml file that the Web Dashboard will use to render it’s content. It’s really important that you add the <xmllogger>. It is required for the Web Dashboard to function properly.

If you are like me and you are using MbUnit as a test tool, you will need to perform some additional step to integrate your results files into the Web Dashboard. The solution is described in the Andrew Stopford’s Weblog. If you don’t see the report after that, verify that MbUnit genarate an xml file instead of an html file.

6. The Web Dashboard

The Web Dashboard is the easiest way to see every test results, builds logs, coverage statistics, etc…

You can access it via the http://nameofyourserver/ccnet.

7. CCTray

CCTray is a little application that helps you monitor your build. Simply access you Web Dashboard, and it the left menu, there is an option to download CCTray.

cctraydownload

Then you need to add the projects you want to monitor. You do that first by entering the name of the server and then selecting the projects you want. I’m usually using the “Connect directly using .NET remoting.

addserver

Keep in mind that it is a basic tutorial and I intend to develop a little more in the following months. In the meanwhile, I will appreciate any comments, suggestion or ideas.

(Put me in your feed reader ! :P)

Posted in Agile, Continuous Integration, Tools | No Comments »

NAnt 0.86 beta 1 is out !!

Posted by Sebastien Lachance on December 10, 2007

NAnt 0.86 beta 1 is out! Now with support for .NET 3.5.

Posted in Tools | No Comments »

Basic Layout of my solution

Posted by Sebastien Lachance on December 6, 2007

(Index of the whole series)

I have completely forgotten to show you the basic folder hierarchy of my solution. I invite you to try once to make a completely different folder hierarchy instead of the one Visual Studio suggest. Not that Visual Studio is a bad tool for this, not at all. I have learned that letting a tool do the folder management can lead on to unnecessarily complexity. Let me explain myself. There is an adage that say you should program into a language instead of programming in a language. Make Visual Studio work with your layout instead of using the default. I find interesting what you can learn when you organize yourself the layout of the solution.

Anyway, let’s see my folder structure :

solutionstructure

The build folder is where the compiled application will reside. When doing automated testing I will use this version.

The config folder is where all the configuration files will be. I’ll probably get rid of it real soon as I have probably found a way that work better for me.

The lib folder contains library that are necessary for the project to be executed correctly.

The sql folder will contains all the sql script. This is also considered to be removed.

The src folder is composed of the app folder and the test folder. Each one contains a subset of all the projects (tests projects in the test folder and application in the app folder).

The tools folder contains any tools that are not necessary to execute the solution but are needed for the development.

It’s basically all I need for now to begin iterating on my application (using User Stories of course). I must mention that I doing this in an iterative way and a lot of things are subject to change. Any comments are greatly appreciated and will be read and considered.

I’m also considering to put all source file into Google Code. Stay tuned!

Posted in Agile, Continuous Integration, Design, Learning, Visual Studio | No Comments »

Setting up the build file

Posted by Sebastien Lachance on December 4, 2007

(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>

Posted in Agile, Learning, Tools, Visual Studio | No Comments »