<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>My view on C# &#187; .NET</title>
	<atom:link href="http://ilmatte.wordpress.com/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://ilmatte.wordpress.com</link>
	<description>Just another C# weblog</description>
	<lastBuildDate>Mon, 02 Mar 2009 14:22:28 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='ilmatte.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/306cbfcf7a1555208a0254b307a55ff1?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>My view on C# &#187; .NET</title>
		<link>http://ilmatte.wordpress.com</link>
	</image>
			<item>
		<title>CruiseControl.Net Tutorial &#8211; Part 2</title>
		<link>http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/</link>
		<comments>http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 22:14:53 +0000</pubDate>
		<dc:creator>ilmatte</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[CruiseControl.NET]]></category>
		<category><![CDATA[Project Management]]></category>
		<category><![CDATA[ccnet]]></category>
		<category><![CDATA[Continuous Integration]]></category>

		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=88</guid>
		<description><![CDATA[
1. Introduction (part 1)
2. Resources (part 1)
3. Installation (part 1)
3.1. Install CruiseControl.NET (part 1)
3.2. Create a CCNet Website in IIS (part 1)
3.3. Install Nunit (part 1)
4. CruiseControl.NET Server Configuration &#8211; General (part 1)
5. Structure of a &#8216;Project&#8217; Configuration File (part 1)
6. Source Control Block (part 1)
7. Trigger Block (part 1)
8. Labeller Block (part 1)
9. Tasks [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=88&subd=ilmatte&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a title="ccnettut2top" name="ccnettut2top"></a><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutintro">1. Introduction (part 1)</a></span><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutresources">2. Resources (part 1)</a></span><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutinstallation">3. Installation (part 1)</a></span><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutinstallccnet">3.1. Install CruiseControl.NET (part 1)</a></span></span><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutiiscreatesite">3.2. Create a CCNet Website in IIS (part 1)</a></span></span><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutinstallnunit">3.3. Install Nunit (part 1)</a></span></span><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutconfiguration">4. CruiseControl.NET Server Configuration &#8211; General (part 1)</a></span><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutprojectconfiguration">5. Structure of a &#8216;Project&#8217; Configuration File (part 1)</a></span><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutsourcecontrolblock">6. Source Control Block (part 1)</a></span><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettuttriggerblock">7. Trigger Block (part 1)</a></span><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutlabellerblock">8. Labeller Block (part 1)</a></span><br />
<a href="#ccnettuttasksblock">9. Tasks Block</a><br />
<a href="#ccnettutmsbuildtask">10. MsBuild Task</a><br />
<span style="position:relative;left:10px;"><a href="#ccnettutreferencepath">10.1. MSBuild and ReferencePath &#8211; CruiseControl.NET not resolving reference to Nunit</a></span><br />
<span style="position:relative;left:10px;"><a href="#ccnettutrodemeyer">10.2. An Alternative MSBuild Logger &#8211; Christian Rodemeyer&#8217;s MsBuildToCCNet</a></span><br />
<span style="position:relative;left:10px;"><a href="#ccnettutwebdashboardimages">10.3. CruiseControl.NET Webdashboard fails in finding images if not installed in virtual directory</a></span><br />
<span style="position:relative;left:10px;"><a href="#ccnettutnumberofprojects">10.4. MSBuildToCCNET reports wrong number of compiled projects</a></span><br />
<span style="position:relative;left:10px;"><a href="#ccnettutassemblylinker">10.5. CruiseControl.NET, MsBuild Task and Resources &#8211; Assembly Linker</a></span><br />
<span style="position:relative;left:10px;"><a href="#ccnettutwebappprojects">10.6. CruiseControl.NET, MsBuild Task and Web Application projects</a></span><br />
<a href="#ccnettutnunittask">11. Nunit Task</a><br />
<span style="position:relative;left:10px;"><a href="#ccnettutnunittask1">11.1. Nunit Task</a></span><br />
<span style="position:relative;left:10px;"><a href="#ccnettutnunittask2">11.2. Executable Task</a></span><br />
<a href="#ccnettutpublishersblock">12. Publishers Block</a><br />
<a href="#ccnettutprebuildblock">13. PreBuild Block</a><br />
<span style="position:relative;left:10px;"><a href="#ccnettutinstallnant">13.1. Install Nant</a></span><br />
<span style="position:relative;left:10px;"><a href="#ccnettutnantfundamentals">13.2. Nant Fundamentals</a></span></p>
<p>This article is the second one of a series dedicated to CruiseControl.Net.<br />
In the first part (which you can find <a title="part1" href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/" target="_blank">here</a>) we installed it and had an overview of how to configure it.<br />
Then we started to configure a project file: we instructed the <strong>Source Control Block</strong> to use Subversion, the <strong>Trigger Block</strong> to check it periodically and the <strong>Labeller Block</strong> to use: svnRevisionLabeller<br />
In this second article we will see the <strong>Tasks Block</strong> and I will point out some issues that might arise and provide solutions as well.</p>
<p>Thanks to Frank Geerlings for making me aware of a casing problem with the xml samples.<br />
By talking with WordPress support it came out that there was a little bug and they suggested me<br />
how to fix the problem.</p>
<h3><a title="ccnettuttasksblock" name="ccnettuttasksblock"></a><span style="font-size:small;color:#993300;">9. Tasks Block</span></h3>
<p>The tasks block represents how the build of the project actually takes place.<br />
In our example we will use an <strong>MsBuild Task</strong> to accomplish the main purpose of our project, which is to compile the versioned Visual Studio solution.<br />
After that we will use an <strong>Executable Task</strong> to run our unit tests, if the build succeeds.<br />
Let&#8217;s see the <a title="ccnettutsamplexml" name="ccnettutsamplexml">whole Tasks Block</a>, at first:</p>
<pre class="brush: xml;">
&lt;tasks&gt;
&lt;!-- compiles working copy -- &gt;
  &lt;msbuild&gt;
    &lt;executable&gt;C:\WINDOWS\Microsoft.NET\Framework\
      v2.0.50727\MSBuild.exe
    &lt;/executable&gt;
    &lt;workingDirectory&gt;C:\develop\CCnet\project1WorkingDir
    &lt;/workingDirectory&gt;
&lt;projectFile&gt;DummySolution.sln&lt;/projectFile &gt;
    &lt;buildArgs&gt;/noconsolelogger /v:quiet
      /p:Configuration=Debug
      /p:ReferencePath=&quot;C:\Program Files\NUnit 2.4.7\bin&quot;
    &lt;/buildArgs&gt;
    &lt;targets&gt;ReBuild&lt;/targets &gt;
    &lt;timeout&gt;600&lt;/timeout &gt;
    &lt;logger&gt;c:\Program Files\CruiseControl.NET\server\
      Rodemeyer.MsBuildToCCNet.dll&lt;/logger &gt;
  &lt;/msbuild&gt;
&lt;!-- launches nunit tests on working copy -- &gt;
  &lt;exec&gt;
    &lt;executable&gt;C:\Program Files\NUnit 2.4.7\
      bin\nunit-console.exe
    &lt;/executable &gt;
    &lt;buildArgs&gt;/xml:..\project1CCnetArtifacts\nunit-results.xml
      /nologo Dummy.sln.nunit
      /exclude:LongRunning,AnotherCategoryName
    &lt;/buildArgs&gt;
  &lt;/exec&gt;
&lt;/tasks&gt;
</pre>
<p>Let&#8217;s focus on the <strong>MsBuild Task</strong> first and see how we can configure and customize it:</p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettuttasksblock"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettutmsbuildtask" name="ccnettutmsbuildtask"></a><span style="font-size:small;color:#993300;">10. MsBuild Task</span></h3>
<p>Let&#8217;s have a look at the meaning of the xml nodes children of the <strong>&lt;msbuild&gt;</strong> node:</p>
<p><strong>&lt;executable&gt;</strong>: contains the path to the msbuild executable file. You don&#8217;t really need to set it because the default value is the standard installation path: <span style="color:#808080;">C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</span>.<br />
I decided to set it explicitly just to be sure about it .<br />
<strong>&lt;workingDirectory&gt;</strong>: is the directory in which MsBuild will be run, so it must be the directory containing our project&#8217;s checked out working copy. You can provide a path relative to the current project&#8217;s workinDirectory but I preferred to provide the full path. Actually, the path to the CCNET checked out working copy is the same as the <strong>&lt;workingDirectory&gt;</strong> field of the <strong>Source Control Block</strong>.<br />
<strong>&lt;projectFile&gt;</strong>: is the name of the project to build. MsBuild accepts a Visual Studio solution file as the project file to build. Obviously the <strong>MsBuild Task</strong> accepts it as well.<br />
<strong>&lt;buildArgs&gt;</strong> This row provides additional command line arguments to MsBuild. We tell it not to log events to the console (<span style="color:#808080;">/noconsolelogger</span>), to build the Debug configuration (<span style="color:#808080;">/p:Configuration=Debug</span>) and to provide a reduced output (<span style="color:#808080;">/v:quiet</span>).<br />
As far as the <span style="color:#808080;">/p:ReferencePath</span> buildArg is concerned it is worth to talk extensively about a problem that could arise with Nunit, so have a look at <a href="#ccnettutreferencepath" target="_self">paragraph 10.1</a>.</p>
<h4><a title="ccnettutreferencepath" name="ccnettutreferencepath"></a><span style="font-size:x-small;color:#993300;">10.1 MSBuild and ReferencePath &#8211; CruiseControl.NET not resolving reference to Nunit</span></h4>
<p>It could happen that CCNET is not able to locate Nunit (or some other dependency assembly) depending on how your project file has been created by Visual Studio.<br />
Open your project file (<strong>DummyProject.csproj</strong>) with a text editor (e.g.: Notepad++). If you find an entry as follows in it:</p>
<pre class="brush: xml;">
&lt;Itemgroup&gt;
  &lt;Reference Include=&quot;nunit.framework, Version=2.4.7.0,
    Culture=neutral, PublicKeyToken=96d09a1eb7f44a77,
    processorArchitecture=MSIL&quot; /&gt;
      ....
&lt;/Itemgroup&gt;
</pre>
<p>with no &lt;HintPath&gt; associated to the Nunit &lt;Reference&gt; it could be that CCNET will not be able to resolve that reference if you don&#8217;t register nunit.framework.dll in the server&#8217;s GAC.</p>
<p>You can make sure that CCNET is able to resolve the dependency by providing an alternative search path in which to look for.<br />
Each assembly referenced in the Visual Studio project file needs to be located by MSBUild at compile time.<br />
The location of the referenced assemblies is resolved by MSBuild by looking in several locations in a particular search order (as explained <a title="reference path vs2005" href="http://blogs.msdn.com/manishagarwal/archive/2005/09/28/474769.aspx" target="_blank">here</a>).<br />
We could modify the .csproj file by providing a  value as a child node of the  node, e.g.:</p>
<pre class="brush: xml;">
&lt;Reference Include=&quot;DummyLibrary, Version=1.0.0.0,
    Culture=neutral, processorArchitecture=MSIL&quot;&gt;
  &lt;SpecificVersion&gt;False&lt;/SpecificVersion&gt;
  &lt;HintPath&gt;..\..\CommonReferencedDLLs\DummyLibrary.dll
  &lt;/HintPath&gt;
&lt;/Reference&gt;
</pre>
<p>This approach has two drawbacks:</p>
<ol>
<li> the hintpath is a relative path, thus making the build success depend on the location of the project relative to the referenced assembly (this could be a problem if we reference an external assembly);</li>
<li>we need to modify each Visual Studio project file by hand  and we don&#8217;t want to do it!</li>
</ol>
<p>Fortunately there&#8217;s an easy way out:<br />
We can override all the project specific settings for path resolving by passing a <strong>ReferencePath </strong>property from the MSBuild command line.<br />
Such property accepts as value a list of paths (<em>MSBuild DummySolution.sln  /p:&#8221;ReferencePath=&lt;Path1;Path2;Path3&gt;&#8221;</em>) and it is checked by the build process before checking other locations (<strong>HintPath</strong> for example).<br />
So the way to provide an alternative search path from the command line is to pass as argument a <strong>ReferencePath</strong> property.<br />
This is the reason why the command line provided in the &lt;buildArgs&gt; field contains the <strong>ReferencePath</strong> property pointing to the Nunit install path:<br />
<span style="color:#808080;">/p:ReferencePath=&#8221;C:\Program Files\NUnit 2.4.7\bin&#8221;</span>.</p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutmsbuildtask"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<p><span style="font-size:x-small;color:#993300;">end of paragraph 10.1</span><br />
<span style="font-size:x-small;color:#993300;">continues paragraph 10. MsBuild Task</span></p>
<p>Let&#8217;s go on with the analysis of the xml nodes children of the &lt;msbuild&gt; node:<br />
<strong>&lt;targets&gt;</strong> specifies which targets to build in this msbuild project file. It represents the MSbuild&#8217;s /target command line argument. We set it to <strong>Rebuild</strong> (clean and build).<br />
<strong>&lt;timeout&gt;</strong> is the number of seconds before assuming that the process has hung. If timeout is exceeded the process will be killed.<br />
<strong>&lt;logger&gt;</strong> specifies the path to the assembly containing the logger to use to format the log output of MSbuild .<br />
If you don&#8217;t want to use the alternative logger that I used in the configuration shown above, you can rely on the default logger as explained here and skip the following<br />
<a href="#ccnettutrodemeyer" target="_self">paragraph 10.2</a>.<br />
To use the default logger:</p>
<ul>
<li>leave out the &lt;logger&gt; field,</li>
<li>download the assembly containing the default xml logger <a title="default logger" href="http://ccnetlive.thoughtworks.com/MSBuildXmlLogger%2DBuilds/" target="_blank">here</a> (find info <a title="loggers description" href="http://confluence.public.thoughtworks.org/display/CCNET/Using+CruiseControl.NET+with+MSBuild" target="_blank">here</a>),</li>
<li>copy the downloaded assembly (<strong>ThoughtWorks.CruiseControl.MSBuild.dll</strong>) to the folder: <span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET\server</span>.</li>
</ul>
<p>I suggest to use the alternative logger (by Christian Rodemeyer) as explained in the following paragraph. The RodeMeyer&#8217;s logger provide lighter msbuild output and his modified stylesheets provide much more readable display of such information.</p>
<h4><a title="ccnettutrodemeyer" name="ccnettutrodemeyer"></a><span style="font-size:x-small;color:#993300;">10.2. An Alternative MSBuild Logger &#8211; Christian Rodemeyer&#8217;s MsBuildToCCNet</span></h4>
<p>I chose to use a logger alternative to the default one: Christian Rodemeyer&#8217;s MsBuildToCCNet.<br />
You can find it at:  <a title="rodemeyer page" href="http://confluence.public.thoughtworks.org/display/CCNETCOMM/Improved+MSBuild+Integration" target="_blank">Improved MSBuild Integration</a>.  From there either you can download separately the assembly and all related stuff needed to correctly display the results from Rodemeyer&#8217;s logger or you can download a zip file with the whole project and source code.</p>
<p>In the page cited above you can find detailed instructions on how the logger works and how it should be configured.<br />
In the current paragraph I&#8217;ll illustrate the installation process and add some useful tips for making it work.<br />
I suggest to download the full project that comes in a zip file named: MsBuildToCCNet.zip (download <a title="download rodemeyer" href="http://confluence.public.thoughtworks.org/download/attachments/6253/MsBuildToCCNet.zip?version=5" target="_blank">here</a>).<br />
Unzipping the package you will have a directory named: MsBuildToCCNet. Inside this directory you will find, among the rest, a directory named <strong>Release</strong>, containing the assembly: <strong>Rodemeyer.MsBuildToCCnet.dll</strong>.<br />
Just copy the assembly to the <span style="color:#808080;">\CruiseControl.NET\server</span> folder (e.g.: <span style="color:#808080;">c:\Program Files\CruiseControl.NET\server\</span>).<br />
There&#8217;s another subdirectory of the <span style="color:#808080;">MsBuildToCCNet</span> folder, named <span style="color:#808080;">ccnet</span> where you can find the resources needed to correctly display the logs produced by Rodemeyer&#8217;s logger. Those resources are:<br />
<strong>cruisecontrol.css</strong> and<br />
<strong>msbuild2ccnet.xsl</strong>.</p>
<p>You need to use those two files and to configure the Webdshboard:</p>
<ol>
<li>Move into your CruiseControl.NET Webdashboard folder, under the path: <span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET\webdashboard</span> (e.g.: <span style="color:#808080;">c:\Program Files\CruiseControl.NET\webdashboard\</span>) and back up the file: <strong>cruisecontrol.css</strong>.<br />
Then replace it with the <strong>cruisecontrol.css</strong> file you found in the Rodemeyer&#8217;s MsBuildToCCNet folder (e.g.: copy <span style="color:#808080;">MsBuildToCCNet\ccnet\cruisecontrol.css</span> to <span style="color:#808080;">c:\Program Files\CruiseControl.NET\webdashboard\cruisecontrol.css</span>);</li>
<li>There&#8217;s a subdirectory of the CruiseControl.NET Webdashboard folder, named: <strong>xsl</strong>.<br />
You need to copy the other resource (<strong>msbuild2ccnet.xsl</strong>) you found in the <span style="color:#808080;">MsBuildToCCNet\ccnet</span> folder in that directory: <span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET\webdashboard\xsl\</span>;</li>
<li>You need to modify the <strong>dashboard.config</strong> file in the CruiseControl.NET Webdashboard folder in order to correctly show the output of the logger.<br />
Being that we&#8217;re talking about the Webdashboard configuration I will show you all the changes you will need to do to let it work with the following three components (even if we&#8217;ll see two of them only in the following paragraphs):</p>
<ul>
<li> MsBuildToCCNet</li>
<li> Nunit integration</li>
<li> FxCop integration</li>
</ul>
<p>First of all choose a 32 x 32 jpg image representing a smiling icon and place it in the CruiseControl.NET Webdashboard folder: <span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET\webdashboard</span>.<br />
Rename the image file: <em>your_happy_image.jpg</em> and, when a new build succeeds, you&#8217;ll obtain a smiling icon in the Webdashboard report! (you can find a sample image <a title="happy image" href="http://ilmatte.files.wordpress.com/2008/06/your_happy_image.jpg" target="_blank">here</a>).<br />
Then open <span style="color:#808080;">CruiseControl.NET\webdashboard\xsl\msbuild2ccnet.xsl</span> and go to line 24:</p>
<pre class="brush: xml;">
&lt;xsl :if test=&quot;@error_count = 0 and @warning_count = 0&quot;&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src=&quot;/ccnet/your_happy_image.jpg&quot;
           alt=&quot;Happy Image <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> &quot; /&gt; Juchuu !!!&lt;/td&gt;
&lt;/tr&gt;
&lt;/xsl&gt;
</pre>
<p>replace the <em>img src</em> attribute: <span style="color:#808080;">/ccnet/your_happy_image.jpg</span> with <span style="color:#808080;">/your_happy_image.jpg</span> if you configured iis with a new website for the webdashboard instead of a virtual directory. If you&#8217;re usign the default virtual directory named <strong>ccnet</strong>, don&#8217;t modify that row.<br />
Next you need to locate the field: <strong>&lt;buildPlugins&gt;</strong> in <span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET\webdashboard\dashboard.config</span> and arrange or delete its children nodes in order to obtain the following configuration (remember to back up the file first):</p>
<pre class="brush: xml;">
&lt;buildplugins&gt;
  &lt;buildreportbuildplugin&gt;
    &lt;xslfilenames&gt;
      &lt;xslfile&gt;xsl\header.xsl&lt;/xslfile&gt;
      &lt;xslfile&gt;xsl\modifications.xsl&lt;/xslfile&gt;
      &lt;xslfile&gt;xsl\msbuild2ccnet.xsl&lt;/xslfile&gt;
      &lt;xslfile&gt;xsl\unittests.xsl&lt;/xslfile&gt;
      &lt;xslfile&gt;xsl\compile.xsl&lt;/xslfile&gt;
      &lt;xslfile&gt;xsl\fxcop-summary.xsl&lt;/xslfile&gt;
    &lt;/xslfilenames&gt;
  &lt;/buildreportbuildplugin&gt;
  &lt;buildlogbuildplugin /&gt;
  &lt;xslreportbuildplugin description=&quot;NUnit Details&quot;
       actionName=&quot;NUnitDetailsBuildReport&quot;
       xslFileName=&quot;xsl\tests.xsl&quot; /&gt;
  &lt;xslreportbuildplugin description=&quot;NUnit Timings&quot;
       actionName=&quot;NUnitTimingsBuildReport&quot;
       xslFileName=&quot;xsl\timing.xsl&quot; /&gt;
   &lt;xslreportbuildplugin description=&quot;FxCop Report&quot;
       actionName=&quot;FxCopBuildReport&quot;
       xslFileName=&quot;xsl\FxCopReport.xsl&quot; /&gt;
&lt;/buildplugins&gt;
</pre>
<p>As you can see, such configuration includes also stylesheet files for nunit and fxcop integration. We will soon configure the server to integrate those components.</li>
</ol>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutmsbuildtask"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<p><span style="font-size:x-small;color:#993300;">end of paragraph 10.2</span><br />
<span style="font-size:x-small;color:#993300;">continues paragraph 10. MsBuild Task</span></p>
<p>While adding the smiling image in the previous paragraph we had to change the path in the xsl file.<br />
The same problem could arise with other stylesheet files if you configured the webdashboard to be a website instead that a virtual directory named ccnet.<br />
Have a look at the next paragraph for details:</p>
<h4><a title="ccnettutwebdashboardimages" name="ccnettutwebdashboardimages"></a><span style="font-size:x-small;color:#993300;">10.3. CruiseControl.NET Webdashboard Fails in Finding Images if Not Installed in Virtual Directory</span></h4>
<p>If you unchecked <span style="color:#808080;">&#8216;Create virtual directory in IIS for Web dashboard&#8217;</span> as shown in part 1 of this tutorial at <a title="install part 1" href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutinstallccnet" target="_blank">3.1. Install CruiseControl.NET</a> and installed the Webdashboard as a new website as shown in the paragraph: <a title="create iis website part 1" href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutiiscreatesite" target="_blank">3.2. Create a CCNet Website in IIS</a>, the webdashboard could have problems in resolving image paths.<br />
You will realize it as soon as you will configure the server to integrate nunit or fxcop (will see it in  following paragraphs).<br />
To make sure not to have this problems you must modify the following files:<br />
<strong>xsl\tests.xsl</strong><br />
<strong>xsl\fxcop-summary.xsl</strong><br />
under: <span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET\webdashboard\</span></p>
<p>you have to replace all the paths relative to the root of the website with relative paths, e.g:</p>
<p>in the file: <strong>xsl\tests.xsl</strong> you should replace all entries like:</p>
<pre class="brush: xml;">
eImg.src = &quot;&lt;xsl :value-of select=&quot;$applicationPath&quot;/&gt;/images/arrow_minus_small.gif&quot;;
</pre>
<p>with:</p>
<pre class="brush: xml;">
eImg.src = &quot;&lt;xsl :value-of select=&quot;$applicationPath&quot;/&gt;images/arrow_minus_small.gif&quot;;
</pre>
<p>and entries like:</p>
<pre class="brush: xml;">
&lt;img src=&quot;{$applicationPath}/images/fxcop-error.gif&quot;/&gt;
</pre>
<p>with:</p>
<pre class="brush: xml;">
&lt;img src=&quot;{$applicationPath}images/fxcop-error.gif&quot;/&gt;
</pre>
<p>that is, you simply need to delete the leading &#8216;forward slash&#8217; at the beginning of the path (just before the &#8216;images&#8217; folder name).</p>
<p>you need to accomplish the same task with the file <strong>xsl\fxcop-summary.xsl</strong>, e.g.:</p>
<p>you should replace entries like:</p>
<pre class="brush: xml;">
&lt;xsl :attribute name=&quot;src&quot;&gt;&lt;xsl :value-of select=&quot;$applicationPath&quot; /&gt;/images/fxcop-critical-error.gif&lt;/xsl&gt;
</pre>
<p>with:</p>
<pre class="brush: xml;">
&lt;xsl :attribute name=&quot;src&quot;&gt;&lt;xsl :value-of select=&quot;$applicationPath&quot; /&gt;images/fxcop-critical-error.gif&lt;/xsl&gt;
</pre>
<p>Actually, you should find all paths to images in those two files and delete the leading forward slash.</p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutmsbuildtask"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<p><span style="font-size:x-small;color:#993300;">end of paragraph 10.3</span><br />
<span style="font-size:x-small;color:#993300;">continues paragraph 10. MsBuild Task</span></p>
<p>Back to the MSBuildToCCNET alternative Logger for MsBuild, I will explain now why I decided to recompile the source code instead of using the assembly provided: <span style="color:#808080;">MsBuildToCCNet\Release\Rodemeyer.MsBuildToCCnet.dll</span></p>
<h4><a title="ccnettutnumberofprojects" name="ccnettutnumberofprojects"></a><span style="font-size:x-small;color:#993300;">10.4. MSBuildToCCNET Reports Wrong Number of Compiled Projects</span></h4>
<p>I found that MsBuildToCCNet reported the wrong number of projects in the webdashboard in the page reporting the details of the last build.<br />
There&#8217;s a row that sounds like the following, displaied in that page:</p>
<p><span style="color:#0000ff;">&#8216;15 Projects built with 2 warnings&#8217;</span></p>
<p>Looking at the source code (in the file: <strong>Logger.cs</strong>) I realized that the list of <em>Project</em> type instances includes the solution file (<span style="color:#666699;">DummySolution.sln</span>) and a <em>Project</em> object named &#8220;<span style="color:#ff6600;">MSBuild</span>&#8220;, somehow representing the MsBuild process.<br />
Appearently this is the reason why the reported number of projects is wrong.<br />
I still haven&#8217;t tried to contact the author so I don&#8217;t know very well how the Logger is supposed to work as far as this count is concerned.<br />
As a workaround I modified the following row:</p>
<pre class="brush: csharp;">
w.WriteAttributeString(&quot;project_count&quot;,
                     XmlConvert.ToString(projects.Count));
</pre>
<p>turning it into:</p>
<pre class="brush: csharp;">
w.WriteAttributeString(&quot;project_count&quot;,
                     XmlConvert.ToString(projects.Count - 2));
</pre>
<p>in the &#8216;WriteLog(XmlWriter w)&#8217; method (file: <strong>Logger.cs</strong> at row 104).</p>
<p>This seems having fixed the problem with no side effects.</p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutmsbuildtask"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<p><span style="font-size:x-small;color:#993300;">end of paragraph 10.4</span><br />
<span style="font-size:x-small;color:#993300;">continues paragraph 10. MsBuild Task</span></p>
<p>You could have problems running msbuild task if your server machine (the one in which you installed CruiseControl.NET) is not updated with all the software installed in a developer workstation. Let&#8217;s see which problems could arise:</p>
<h4><a title="ccnettutassemblylinker" name="ccnettutassemblylinker"></a><span style="font-size:x-small;color:#993300;">10.5. CruiseControl.NET, MsBuild Task and Resources &#8211; Assembly Linker</span></h4>
<p>If you want to provide localization for any of your projects or somehow use resources files (.resx) you will get an error during the build on the CruiseControl.NET server if MsBuild is not able to locate the Assembly Linker.<br />
The error should look something like:</p>
<p><span style="color:#ff0000;">C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1950,9): error MSB3011: &#8220;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\AL.exe&#8221; was not found. Either 1) Install the .NET Framework SDK, which will install AL.exe. Or 2) Pass the correct location of AL.exe into the &#8220;ToolPath&#8221; parameter of the AL task.</span></p>
<p>AL.exe is used to produce the satellite assemblies and the executable file is placed in the .NET framework directory.<br />
But Al.exe is a .Net Framework SDK tool. It is not included in .Net Framework 2.0 runtime installation.<br />
You need to install the .NET framework SDK on the server machine if you don&#8217;t want to encounter this problem.<br />
If you want to solve this particular issue in a tricky way without installing the whole SDK, you can copy <strong>al.exe.config</strong> e <strong>al.exe</strong> from a developer workstation and place them in the <span style="color:#808080;">C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727</span> directory on the server machine.<br />
This is how I solved the problem but I suggest you to install the .NET framework SDK on the server machine.</p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutmsbuildtask"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h4><a title="ccnettutwebappprojects" name="ccnettutwebappprojects"></a><span style="font-size:x-small;color:#993300;">10.6. CruiseControl.NET, MsBuild Task and Web Application projects</span></h4>
<p>A particular note is due for Web projects.<br />
Updating Visual Studio 2005 you get the SP1. Together with the Service Pack 1 for Visual Studio you get the WebApplication project template.<br />
Such template lets us add a new kind of project to our solution: a web site project structured exactly like any other Visual Studio project.<br />
So you can quit creating new websites (<strong>File &#8211;&gt; New &#8211;&gt; Web Site&#8230;</strong>) and start creating new WebApplication projects (<strong>File &#8211;&gt; New &#8211;&gt; Project&#8230;</strong> and then choose &#8216;<strong>ASP.NET Web Application</strong>&#8216;).</p>
<p>In order to use WebApplication projects you need to have Visual Studio installed on your machine and the WebApplication project plugin (that comes with the Visual Studio 2005 SP1).<br />
If the server in which CruiseControl.NET server is running is not a develpment workstation you will get an error when trying to build a WebApplication project, beacuse you miss those two prerequisites.</p>
<p>You can easily fix this problem: you simply need to copy the file: <strong>Microsoft.WebApplication.targets</strong> that you can find under:<br />
<span style="color:#808080;">&#8220;C:\Program Files\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications\&#8221;</span><br />
from a development workstation and paste it to the corresponding path on the server machine (creating the directories in the path if needed).</p>
<p>Additionally, if you&#8217;re using an ASP.NET AJAX Enabled WebApplication as the web project template you need to install the aspnet-ajax extensions as well.<br />
You can find the installer (ASPAJAXExtSetup.msi) for .NET framework 2.0 <a title="asp.net ajax download" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&amp;displaylang=en" target="_blank">here</a></p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutmsbuildtask"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettutnunittask" name="ccnettutnunittask"></a><span style="font-size:small;color:#993300;">11. Nunit Task</span></h3>
<p>The second Task Block that you find in the xml fragment <a title="xml msbuild task" href="#ccnettutsamplexml" target="_self">above</a> is an Executable Task used to instruct CruiseControl.NET to run unit tests with Nunit.</p>
<p>At first I tried to use a <strong>Nunit Task Block</strong> but I soon realized that it was not good for me because it was not possible to provide arguments to the task that should be used as arguments of the Nunit command-line executable.</p>
<p>This is a problem because there&#8217;s no way to let the Nunit task be aware of Nunit categories.<br />
For those who don&#8217;t know, Nunit lets you specify a &#8216;<em>Category</em>&#8216; attribute in test methods, with the following syntax:</p>
<pre class="brush: csharp;">
[Test]
[Category(&quot;LongRunning&quot;)]
public void VeryLongTest()
{ /* ... */ }
</pre>
<p>This attribute allows you to instruct Nunit to treat all the methods belonging to the same category in the same way.<br />
Usually what we want to do is to exclude a cluster of tests from running.<br />
Typically we exclude tests that take too much to run, using the following syntax with the nunit command-line tool:</p>
<p><strong>nunit-console.exe /exclude:LongRunning,AnotherCategoryName</strong></p>
<p>You can configure excluded categories in nunit GUI as well, by clicking the &#8216;<strong>Categories</strong>&#8216; tab in the top left corner.<br />
A list of available categories will be shown. Just select the categories of interest and click the <strong>Add</strong> button.<br />
Then check the <strong>Exclude these categories</strong> checkbox at the bottom of the page and run the nunit project.</p>
<p>It is very useful to be able to exclude some categories of tests from the continuous integration environment, still being able to run them on developer machines.</p>
<p>This is the reason why I recently submitted a patch to CruiseControl.Net adding support for Nunit categories.<br />
It&#8217;s not included in the official release yet, because I submitted it too late for this purpose.<br />
However you can find it in the current build which is publicly available at: <a href="http://ccnetlive.thoughtworks.com/CCNet-builds/">ccnetlive</a>. The patch is included starting from build: <a href="http://ccnetlive.thoughtworks.com/CCNet-builds/1.4/1.4.0.3591/CruiseControl.NET-1.4.0.3591.zip">3591</a>.<br />
So now you have two chances to use categories:</p>
<ol>
<li>If you really want to use the last officially released version, read the <a href="#ccnettutnunittask2">paragraph 11.2</a> about how to use an Executable Task (the method described can be useful also if you want to use any other unsupported Nunit command line argument);</li>
<li><span style="text-decoration:underline;">Instead if you can download the latest build from ccnetlive you will be able to specify categories</span> inside the Nunit Task block, as explained in <a href="#ccnettutnunittask">paragraph 11.1</a></li>
</ol>
<h4><a title="ccnettutnunittask1" name="ccnettutnunittask1"></a><span style="font-size:x-small;color:#993300;">11.1. Nunit Task</span></h4>
<p>If you downloaded the most recent build and followed the installation instructions (see: <a href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutinstallation">3. Installation</a>) you can go on reading this paragraph.<br />
If you installed the official release or a build older than 1.4.0.3591, you can still modify your installation with the following instructions:</p>
<p>download the zipped package (<a href="http://ccnetlive.thoughtworks.com/CCNet-builds/1.4/1.4.0.3591/CruiseControl.NET-1.4.0.3591.zip">here</a>) or source code. Unzip it in a temporary directory and locate the assembly: ThoughtWorks.CruiseControl.Core.dll (which, for the zip package, is in the directory: &#8217;server&#8217;).<br />
Copy and replace it to the original one in your CCNET installation directory (back up the original one first) that should be: <span style="color:#808080;">Program Files\CruiseControl.NET\server</span>.</p>
<p>That&#8217;s it! Now you can use the CruiseControl.NET&#8217;s Nunit Task Block also for specifying Nunit categories (see: <a href="http://www.nunit.org/index.php?p=category&amp;r=2.4.8">Nunit categories</a> for reference).</p>
<p>It is possible to specify a list of the categories of tests that we want to be excluded.<br />
It is possible, as well, to specify a list of the only categories that we want to be included as allowed by the Nunit Command-line or GUI interface.<br />
The configuration syntax for the Nunit task becomes:</p>
<pre class="brush: xml;">
&lt;nunit&gt;
&lt;path&gt;C:\Program Files\NUnit 2.4.7\bin\nunit-console.exe
&lt;/path&gt;
    &lt;assemblies&gt;
        &lt;assembly&gt;Dummy.sln.nunit&lt;/assembly&gt;
    &lt;/assemblies&gt;
    &lt;excludedCategories&gt;
        &lt;excludedCategory&gt;LongRunning&lt;/excludedCategory&gt;
	&lt;excludedCategory&gt;Category 2&lt;/excludedCategory&gt;
    &lt;/excludedCategories&gt;
&lt;/nunit&gt;
</pre>
<p>for excluded categories, or:</p>
<pre class="brush: xml;">
&lt;nunit&gt;
&lt;path&gt;C:\Program Files\NUnit 2.4.7\bin\nunit-console.exe
&lt;/path&gt;
    &lt;assemblies&gt;
        &lt;assembly&gt;Dummy.sln.nunit&lt;/assembly&gt;
    &lt;/assemblies&gt;
    &lt;includedCategories&gt;
        &lt;includedCategory&gt;LongRunning&lt;/includedCategory&gt;
	&lt;includedCategory&gt;Category 2&lt;/includedCategory&gt;
    &lt;/includedCategories&gt;
&lt;/nunit&gt;
</pre>
<p>for included categories. You can find the official reference at <a href="http://confluence.public.thoughtworks.org/display/CCNET/NUnit+Task" target="_blank">this page</a> on the official website.</p>
<p>The Nunit task output log file is automatically integrated in the CCNET build results.<br />
So you don&#8217;t need to specify the Merge task (needed if you use the procedure explaine in paragraph 11.2 instead of this one) in the Publishers block as explained in <a href="#ccnettutpublishersblock">paragraph 12</a>:</p>
<pre class="brush: xml;">
&lt;merge&gt;
  &lt;files&gt;
    &lt;file&gt;..\project1CCnetArtifacts\nunit-results.xml&lt;/file&gt;
  &lt;/files&gt;
&lt;/merge&gt;
</pre>
<p>Instead you still need to delete the previous Nunit log file before each build process as explained in the <a href="#ccnettutprebuildblock">paragraph 13 &#8211; PreBuild Block</a>.</p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutnunittask"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h4><a title="ccnettutnunittask2" name="ccnettutnunittask2"></a><span style="font-size:x-small;color:#993300;">11.2. Executable Task</span></h4>
<p>If you&#8217;re working with the official release of CruiseControl.Net (release 1.4) Nunit Task Block syntax only allows you to specify the target solution and little more. In our example it would be:</p>
<pre class="brush: xml;">
&lt;nunit&gt;
&lt;path&gt;C:\Program Files\NUnit 2.4.7\bin\nunit-console.exe
&lt;/path&gt;
	&lt;assemblies&gt;
		&lt;assembly&gt;Dummy.sln.nunit&lt;/assembly&gt;
	&lt;/assemblies&gt;
&lt;/nunit&gt;
</pre>
<p>where <strong>Dummy.sln.nunit</strong> is the Nunit project file for our solution.</p>
<p>The solution I strongly suggest is to replace the Nunit Task with an Executable Task like the one shown below:</p>
<pre class="brush: xml;">
&lt;exec&gt;
  &lt;executable&gt;
    C:\Program Files\NUnit 2.4.7\bin\nunit-console.exe
  &lt;/executable&gt;
  &lt;buildArgs&gt;/xml:..\project1CCnetArtifacts\nunit-results.xml
    /nologo Dummy.sln.nunit
    /exclude:LongRunning,AnotherCategoryName
  &lt;/buildArgs&gt;
&lt;/exec&gt;
</pre>
<p>You only need to specify the full path to the Nunit command-line executable file in the <strong>&lt;executable&gt;</strong> field and the command-line arguments in the <strong>&lt;buildArgs&gt;</strong> field.</p>
<p>In the <strong>&lt;buildArgs&gt;</strong> field you specify arguments as if provided directly to <strong>nunit-console.exe</strong>:</p>
<ol>
<li>specify the path to the file in which nunit will write its output: <span style="color:#808080;">/xml:..\project1CCnetArtifacts\nunit-results.xml</span>.<br />
The file should be produced in the artifactDirectory of the current CCNET project.<br />
By default the executable run by an executable task is run in the Project Working Directory, so the path to the output file is relative to such directory.</li>
<li> You can pass many things as Nunit targets (assemblies, Visual Studio projects or Nunit project files). I suggest to create an Nunit project and pass it as argument to <strong>nunit-console.exe</strong> as shown in the sample above (where the nunit project file is called: <strong>Dummy.sln.nunit</strong>).</li>
<li> you can then add: <span style="color:#808080;">/exclude:LongRunning,AnotherCategoryName</span> thus excluding unwanted tests.</li>
</ol>
<p>Specifying the name of the output file is not enough.<br />
In order to make the output written by nunit in the file nunit-results.xml (arbitrary name specified in the buildArgs tag), available to CruiseControl.NET we need to use a File Merge Task.<br />
If we used Nunit task the output file would have been automatically merged with other output for CruiseControl.NET.<br />
Using the Executable Task we need to explicitly configure CruiseControl.NET to merge the Nunit output file in the log file parsed by CruiseControl.NET.<br />
We will tell CruiseControl.NET to do it at the end of the build process, namely in the Publishers section.</p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutnunittask2"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettutpublishersblock" name="ccnettutpublishersblock"></a><span style="font-size:small;color:#993300;">12. Publishers Block</span></h3>
<p>We will add a <strong>File Merge Task</strong> at the beginning of the Publishers section. You can see below the publishers section as it is defined in our project configuration file:</p>
<pre class="brush: xml;">
&lt;publishers&gt;
  &lt;merge&gt;
    &lt;files&gt;
      &lt;file&gt;..\project1CCnetArtifacts\nunit-results.xml
      &lt;/file&gt;
    &lt;/files&gt;
  &lt;/merge&gt;
  &lt;xmllogger /&gt;
  &lt;statistics /&gt;
  &lt;modificationHistory onlyLogWhenChangesFound=&quot;true&quot; /&gt;
  &lt;artifactcleanup cleanUpMethod=&quot;KeepLastXBuilds&quot;
    cleanUpValue=&quot;20&quot; /&gt;
      ...
&lt;/publishers&gt;
</pre>
<p>The File Merge Task specifies the paths to the files that we want to be merged by the <strong>Xml Log Publisher Task</strong> with the rest of its own output (you don&#8217;t need to specify nunit output file if you used the Nunit Task as in paragraph <a href="#ccnettutnunittask1">11.1. Nunit Task</a>).<br />
All of this output is placed by default in the <strong>buildlogs</strong> directory under the Project&#8217;s Artifact Directory.<br />
So the <strong>File Merge Task</strong> should appear before the <strong>Xml Log Publisher Task</strong> in the publishers section.<br />
The <strong>Xml Log Publisher Task</strong> (&#8216;<strong>xmllogger</strong>&#8216;) is needed for making the web dashboard work correctly.<br />
The &#8216;<strong>statistics</strong>&#8216; field collects and updates statistics for each build. You can see them clicking: <strong>View Statistics</strong> on the left side of the Web Dashboard.<br />
The &#8216;<strong>modificationHistory</strong>&#8216; field logs all the modifications for each build. With <strong>onlyLogWhenChangesFound</strong> you can choose to log info only for builds happened when changes take place (not for forced builds). You can see the modification history by clicking: <strong>View Modification History</strong> on the left side of the Web Dashboard.</p>
<p>I then added an &#8216;<strong>artifactcleanup</strong>&#8216; field in order to keep memory of the last 20 builds only.<br />
This task allows us to choose between two clean up modes of the past build logs:<br />
- deleting logs older than a specified number of days<br />
- keeping only a specified number of logs: the more recent ones (cleanUpMethod=&#8221;KeepLastXBuilds&#8221;)</p>
<p>In the sample above we typed the second choice specifying 20 as cleanUpValue thus telling CruiseControl.NET to keep the log files for the last 20 builds only.</p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutpublishersblock"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettutprebuildblock" name="ccnettutprebuildblock"></a><span style="font-size:small;color:#993300;">13. PreBuild Block</span></h3>
<p>There&#8217;s another issue to solve when integrating Nunit using either an <strong>Exec Task</strong> or the <strong>Nunit Task</strong>: the Nunit log file is not deleted after the build succeeds or fails.<br />
So upon the next build we&#8217;ll still have the old Nunit log file until the Task running Nunit is executed.<br />
To understand what I&#8217;m going to explain now, keep in mind that if a task in the <strong>Tasks Block</strong> fails all the subsequent tasks in the block will be skipped while the tasks in the <strong>Publishers Block</strong> will be executed.</p>
<p>If, during the next build, the <strong>MSBuild Task</strong> fails, the <strong>Exec Task (Nunit Task)</strong> launching Nunit isn&#8217;t executed at all so the <strong>File Merge Task</strong> will merge the previous Nunit log file with the current <strong>Xml Log Publisher</strong> output, thus leading to an incorrect report: still displaying the Nunit results relative to the previous build.<br />
We would obtain the <span style="text-decoration:underline;">current</span> MSBuild report but the <span style="text-decoration:underline;">old</span> Nunit report.<br />
This behavior can lead to misunderstanding of the results so it is a good practice to delete the old Nunit log file before every new build takes place.</p>
<p>The place to accomplish this task is the <strong>PreBuild Block</strong>.<br />
I used a <strong>Nant</strong> build file to drive the steps needed to obtain the desired result (simply delete a file if it exists).</p>
<h4><a title="ccnettutinstallnant" name="ccnettutinstallnant"></a><span style="font-size:x-small;color:#993300;">13.1. Install Nant</span></h4>
<p>You need to install the <a title="nant homepage" href="http://nant.sourceforge.net/" target="_blank">Nant</a> Build tool on the server machine.<br />
Just download the zip package: nant-0.85-bin.zip from <a title="nant download" href="http://downloads.sourceforge.net/nant/nant-0.85-bin.zip?modtime=1160813010&amp;big_mirror=0" target="_blank">here</a> and unzip it into the folder: <span style="color:#808080;">C:\Program Files\Nant</span>.</p>
<h4><a title="ccnettutnantfundamentals" name="ccnettutnantfundamentals"></a><span style="font-size:x-small;color:#993300;">13.2. Nant Fundamentals</span></h4>
<p><strong>Nant</strong> is a build tool driven by xml configuration files (Nant build files).<br />
When you call nant.exe from the command line and you don&#8217;t specify a build file (you can specify one passing as argument: <span style="color:#ff6600;">-buildfile:pathToDir\FileName.build</span>) NAnt looks for a file ending with .build (e.g.: NAnt.build) in the current directory. If it finds such file, it uses it as the reference for the tasks to execute.</p>
<p>The file structure is shown in the following sample xml file:</p>
<pre class="brush: xml;">
&lt; ?xml version=&quot;1.0&quot;?&gt;
&lt;project name=&quot;dummy&quot; default=&quot;target1&quot; basedir=&quot;.&quot;&gt;
	&lt;description&gt;dummy project&lt;/description&gt;
	&lt;target name=&quot;target1&quot; description=&quot;target1 description&quot;&gt;
	    ... (a list of Nant tasks will be placed here)
	&lt;/target&gt;
	&lt;target name=&quot;target2&quot; description=&quot;target2 description&quot;&gt;
		&lt;delete file=&quot;pathToFile\FileName&quot;
                failonerror=&quot;false&quot; /&gt;
		... (a list of other Nant tasks will be placed here)
	&lt;/target&gt;
&lt;/project&gt;
</pre>
<p>A build file contains one <strong>&lt;project&gt;</strong> field with one or more children <strong>&lt;target&gt;</strong> fields each containing different Nant tasks (e.g.: the <strong>&lt;delete&gt;</strong> task).<br />
When invoking <strong>nant.exe</strong> you can specify the name of the target to be executed and Nant will execute all the tasks contained in that target. If you don&#8217;t provide a target, the default one will be executed (i.e. the one specified in the &#8216;<span style="color:#ff6600;">default</span>&#8216; attribute of the <strong>&lt;project&gt;</strong> field).</p>
<p><span style="font-size:x-small;color:#993300;">end of paragraph 13.2</span><br />
<span style="font-size:x-small;color:#993300;">continues paragraph 13. PreBuild Block</span></p>
<p>Once you&#8217;ve got Nant installed on the server machine you have to create a file named nant.build and place it, for convenience, in the directory in which you placed all the CruiseControl.NET related stuff (in this example: <span style="color:#808080;">C:\develop\CCnet</span>).</p>
<p>At the moment we need just one target to delete Nunit log files. Later we will add another target.<br />
The actual file content is the following:</p>
<pre class="brush: xml;">
&lt; ?xml version=&quot;1.0&quot;?&gt;
&lt;project name=&quot;Dummy&quot; default=&quot;cleanNunit&quot; basedir=&quot;.&quot;&gt;
  &lt;description&gt;CCNET Tasks&lt;/description&gt;
  &lt;target name=&quot;cleanNunit&quot;
         description=&quot;removes nunit log file&quot;&gt;
    &lt;delete file=&quot;${CCNetArtifactDirectory}\nunit-results.xml&quot;
          failonerror=&quot;false&quot; /&gt;
  &lt;/target&gt;
&lt;/project&gt;
</pre>
<p>When we tell Nant to execute the &#8216;<span style="color:#ff6600;">cleanNunit</span>&#8216; target, the delete task will be executed and the <strong>nunit-results.xml</strong> file will be deleted.<br />
We use one of the environment variables provided by CCNET to retrieve the path to the artifact directory: <span style="color:#ff6600;">${CCNetArtifactDirectory}</span> so this Nant build file will only work when run from CruiseControl.NET.</p>
<p>In the <strong>Prebuild Block</strong> we will instruct CruiseControl.NET to run a Nant task by adding a CruiseControl.NET <strong>Nant Task Block</strong>.<br />
Such block lets us instruct CruiseControl.NET to execute Nant and lets us specify a Nant build file and the list of Nant targets to execute.<br />
Remember that we named the build file: <strong>nant.build</strong> and we placed it in the directory: <span style="color:#808080;">C:\develop\CCnet</span>.<br />
Now we provide this information to the CruiseControl.NET <strong>Nant Task Block</strong> as shown in the following example:</p>
<pre class="brush: xml;">
&lt;prebuild&gt;
&lt;!-- clean nunit output to avoid CCNET reporting
       about previous build tests if current build fails --&gt;
  &lt;nant&gt;
    &lt;executable&gt;C:\Program Filse\Nant\bin\nant.exe
    &lt;/executable&gt;
    &lt;baseDirectory&gt;C:\develop\CCnet&lt;/baseDirectory&gt;
    &lt;nologo&gt;false&lt;/nologo&gt;
    &lt;buildFile&gt;nant.build&lt;/buildFile&gt;
    &lt;targetList&gt;
      &lt;target&gt;cleanNunit&lt;/target&gt;
    &lt;/targetList&gt;
  &lt;/nant&gt;
&lt;/prebuild&gt;
</pre>
<p>the <strong>&lt;executable&gt;</strong> field specifies the path to the version of nant.exe you want to run,<br />
the <strong>&lt;baseDirectory&gt;</strong> specifies the directory to run the NAnt process in,<br />
<strong>&lt;nologo&gt;</strong> passes the -nologo argument to the Nant command line,<br />
<strong>&lt;buildFile&gt;</strong> specifies the path to the build file to use (relative to the <strong>&lt;baseDirectory&gt;</strong>),<br />
<strong>&lt;targetList&gt;</strong> is used to specify a list of targets, each one in a <strong>&lt;target&gt;</strong> field.</p>
<p>Now we can be sure that each build has the Nunit log file deleted before being executed.</p>
<p><a href="#ccnettut2top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutprebuildblock"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<p><a title="tutorial part 1" href="http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/" target="_self">&lt;&lt; CruiseControl.Net Tutorial &#8211; Part 1</a></p>
<h2><span style="color:#ff0000;"><br />
As soon as possible I will post the third and last part of this tutorial<br />
</span></h2>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filmatte.wordpress.com%2f2008%2f06%2f15%2fcruisecontrolnet-tutorial-part-2%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filmatte.wordpress.com%2f2008%2f06%2f15%2fcruisecontrolnet-tutorial-part-2%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ilmatte.wordpress.com/88/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ilmatte.wordpress.com/88/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilmatte.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilmatte.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilmatte.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilmatte.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilmatte.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilmatte.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilmatte.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilmatte.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilmatte.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilmatte.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=88&subd=ilmatte&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3cb2e7cb9a15640aab9ac6639d9bc462?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filmatte.wordpress.com%2f2008%2f06%2f15%2fcruisecontrolnet-tutorial-part-2%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>CruiseControl.Net Tutorial &#8211; Part 1</title>
		<link>http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/</link>
		<comments>http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 22:15:59 +0000</pubDate>
		<dc:creator>ilmatte</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[CruiseControl.NET]]></category>
		<category><![CDATA[Project Management]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ccnet]]></category>
		<category><![CDATA[Continuous Integration]]></category>

		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=50</guid>
		<description><![CDATA[
1. Introduction
2. Resources
3. Installation
3.1. Install CruiseControl.NET
3.2. Create a CCNet Website in IIS
3.3. Install Nunit
4. CruiseControl.NET Server Configuration &#8211; General
5. Structure of a &#8216;Project&#8217; Configuration File
6. Source Control Block
7. Trigger Block
8. Labeller Block
9. Tasks Block (part 2)
10. MsBuild Task (part 2)
10.1. MSBuild and ReferencePath &#8211; CruiseControl.NET not resolving reference to Nunit (part 2)
10.2. An Alternative MSBuild [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=50&subd=ilmatte&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a title="ccnettut1top" name="ccnettut1top"></a><br />
<a href="#ccnettutintro">1. Introduction</a><br />
<a href="#ccnettutresources">2. Resources</a><br />
<a href="#ccnettutinstallation">3. Installation</a><br />
<span style="position:relative;left:10px;"><a href="#ccnettutinstallccnet">3.1. Install CruiseControl.NET</a></span><br />
<span style="position:relative;left:10px;"><a href="#ccnettutiiscreatesite">3.2. Create a CCNet Website in IIS</a></span><br />
<span style="position:relative;left:10px;"><a href="#ccnettutinstallnunit">3.3. Install Nunit</a></span><br />
<a href="#ccnettutconfiguration">4. CruiseControl.NET Server Configuration &#8211; General</a><br />
<a href="#ccnettutprojectconfiguration">5. Structure of a &#8216;Project&#8217; Configuration File</a><br />
<a href="#ccnettutsourcecontrolblock">6. Source Control Block</a><br />
<a href="#ccnettuttriggerblock">7. Trigger Block</a><br />
<a href="#ccnettutlabellerblock">8. Labeller Block</a><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettuttasksblock">9. Tasks Block (part 2)</a><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutmsbuildtask">10. MsBuild Task (part 2)</a><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutreferencepath">10.1. MSBuild and ReferencePath &#8211; CruiseControl.NET not resolving reference to Nunit (part 2)</a></span><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutrodemeyer">10.2. An Alternative MSBuild Logger &#8211; Christian Rodemeyer&#8217;s MsBuildToCCNet (part 2)</a></span><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2#ccnettutwebdashboardimages">10.3. CruiseControl.NET Webdashboard fails in finding images if not installed in virtual directory (part 2)</a></span><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2#ccnettutnumberofprojects">10.4. MSBuildToCCNET reports wrong number of compiled projects (part 2)</a></span><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2#ccnettutassemblylinker">10.5. CruiseControl.NET, MsBuild Task and Resources &#8211; Assembly Linker (part 2)</a></span><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2#ccnettutwebappprojects">10.6. CruiseControl.NET, MsBuild Task and Web Application projects (part 2)</a></span><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutnunittask">11. Nunit Task (part 2)</a><br />
<span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutnunittask1">11.1. Nunit Task (part 2)</a></span><br />
<span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutnunittask2">11.2. Executable Task (part 2)</a></span><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutpublishersblock">12. Publishers Block (part 2)</a><br />
<span style="background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutprebuildblock">13. PreBuild Block (part 2)</a><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2#ccnettutinstallnant">13.1. Install Nant (part 2)</a></span><br />
<span style="background-color:#ce9d84;"><span style="position:relative;left:10px;background-color:#ce9d84;"><a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2#ccnettutnantfundamentals">13.2. Nant Fundamentals (part 2)</a></span></span></p>
<h3><a title="ccnettutintro" name="ccnettutintro"></a><span style="font-size:small;color:#993300;">1. Introduction</span></h3>
<p>In this article series I will review the various steps needed to setup and configure a working CruiseControl.Net server.<br />
The goal is to set up a Continuous Integration process for a sample project as close as possible to a real-life project.<br />
I will point out several issues that might arise and I will provide solutions as well.<br />
I will try to underline all the details that you need to be aware of.</p>
<p>Thanks to Frank Geerlings for making me aware of a casing problem with the xml samples.<br />
By talking with WordPress support it came out that there was a little bug and they suggested me<br />
how to fix the problem.</p>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a title="ccnettutresources" name="ccnettutresources"></a><span style="font-size:small;color:#993300;">2. Resources</span></h3>
<p>During the article I will guide you through the installation process of the following software:</p>
<p><a title="Subversion" href="http://subversion.tigris.org/" target="_blank">Subversion</a><br />
<a title="CCNET" href="http://ccnet.thoughtworks.com" target="_blank"> CruiseControl.NET</a><br />
<a title="Nunit" href="http://www.nunit.org/index.php" target="_blank">Nunit</a></p>
<p><a title="Nant" href="http://nant.sourceforge.net/" target="_blank">Nant</a><br />
<a title="Fxcop" href="http://blogs.msdn.com/fxcop/" target="_blank">FxCop</a><br />
<a title="nantcontrib" href="http://nantcontrib.sourceforge.net/" target="_blank">NantContrib</a></p>
<p>The following are optional:</p>
<p><a title="TortoiseSVN" href="http://tortoisesvn.tigris.org/" target="_blank">TortoiseSVN</a><br />
<a title="AnkhSVN" href="http://ankhsvn.open.collab.net/" target="_blank">AnkhSVN</a></p>
<p>You can find information about how to install: <a title="Subversion" href="http://subversion.tigris.org/" target="_blank">Subversion</a>, <a title="TortoiseSVN" href="http://tortoisesvn.tigris.org/" target="_blank">TortoiseSVN</a> and <a title="AnkhSVN" href="http://ankhsvn.open.collab.net/" target="_blank">AnkhSVN</a> in the article: <a title="subversion tutorial" href="http://ilmatte.wordpress.com/2008/04/27/guide-to-versioning-a-visual-studio-solution-with-subversion-tortoisesvn-and-ankhsvn/" target="_blank">Guide to Versioning a Visual Studio Solution with Subversion, TortoiseSVN and AnkhSVN</a>.<br />
There you can also find a quick guide about how to create a Subversion repository and how to add a Visual Studio solution to source control.</p>
<p>This tutorial assumes that you have Subversion 1.4.6 installed and that you have configured a Subversion repository at the url: <span style="color:#808080;">svn://localhost/trunk</span> as shown in the article: <a title="subversion tutorial" href="http://ilmatte.wordpress.com/2008/04/27/guide-to-versioning-a-visual-studio-solution-with-subversion-tortoisesvn-and-ankhsvn/" target="_blank">Guide to Versioning a Visual Studio Solution with Subversion, TortoiseSVN and AnkhSVN</a>.</p>
<p>If you already have a working environment with a repository and versioned files, you can go on reading and replace the paths and names in the examples with the paths and names in your environment.</p>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutresources"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettutinstallation" name="ccnettutinstallation"></a><span style="font-size:small;color:#993300;">3. Installation</span></h3>
<ul>
<li><a href="#ccnettutinstallccnet">3.1. Install CruiseControl.NET</a></li>
<li><a href="#ccnettutiiscreatesite">3.2. Create a CCNet Website in IIS</a></li>
<li><a href="#ccnettutinstallnunit">3.3. Install Nunit</a></li>
</ul>
<p>This tutorial will assume that you install CruiseControl.NET on the same machine on which you had installed the Subversion repository. So, first of all, let&#8217;s go through the steps needed to install CruiseControl.NET on your server machine.</p>
<h4><a title="ccnettutinstallccnet" name="ccnettutinstallccnet"></a><span style="font-size:x-small;color:#993300;">3.1. Install CruiseControl.NET</span></h4>
<p>Download the latest <a title="CCNET" href="http://ccnet.thoughtworks.com" target="_blank">CruiseControl.NET</a> release from: <a title="ccnet download" href="http://sourceforge.net/project/showfiles.php?group_id=71179&amp;package_id=83198" target="_blank">SourceForge</a> or the latest build from <a title="ccnet last build" href="http://ccnetlive.thoughtworks.com/CCNet-builds/" target="_blank">CCNetLive</a>.<br />
You can find release notes <a title="ccnet release notes" href="http://confluence.public.thoughtworks.org/display/CCNET/Download" target="_blank">here</a>. For this article I used the installer for version 1.4 (CruiseControl.NET-1.4-Setup.exe), downloaded from the CCNetLive website.</p>
<p>Run the setup executable file and, when prompted, you must specify your choices for a couple of actions:<br />
<span style="color:#808080;">&#8216;Install CC.Net server as windows service&#8217;</span> must be checked so that the setup will install CruiseControl as a Windows service.<br />
In the Services management console the CruiseControl service will be displayed with the name: <em>CruiseControl.NET</em>.<br />
<span style="color:#808080;">&#8216;Create virtual directory in IIS for Web dashboard&#8217;</span> will create a virtual directory named <em>ccnet</em> in the machine&#8217;s IIS web server. If you have an IIS server installation supporting multiple web sites (this is not the case for Windows XP Professional) and prefer to have a separate web site for the CCNet web dashboard you should uncheck this option. This is my choice. In the next paragraph I will show you how to create an IIS web site for the CruiseControl.NET web dashboard.</p>
<p>When the install process is finished all the content will be installed in the folder:<br />
<span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET</span> (e.g. <span style="color:#808080;">C:\Program Files\CruiseControl.NET</span>).<br />
Under this path you will find a directory called <em>server</em>, containing all the CCNet binary files and executables, and a directory called <em>webdashboard</em>, containing the CruiseControl.NET web interface.</p>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutinstallation"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h4><a title="ccnettutiiscreatesite" name="ccnettutiiscreatesite"></a><span style="font-size:x-small;color:#993300;">3.2. Create a CCNet Website in IIS</span></h4>
<p>Here I will add and configure a Website in IIS for the CruiseControl.NET Webdashboard: the administrative interface of CruiseControl.NET.<br />
Open <strong>IIS Manager</strong> in <strong>Administrative Tools</strong>, right-click on the <strong>Web Sites</strong> node and select <strong>New Web Site</strong>.<br />
The Web site creation wizard will start.<br />
Click Next and you will be prompted for a Web Site Description.<br />
Type CCNet and click Next, leave Unassigned the IPAddress, choose a port number (say: 222) and leave empty the &#8216;Host Header for this site&#8217; field, then click Next.<br />
Choose <span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET\webdashboard</span> as the path for the Website and click Next.<br />
Allow &#8216;Read&#8217; and &#8216;Run scripts&#8217;, the default, and click Next. The wizard is finished and the new Website created.</p>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutiiscreatesite"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h4><a title="ccnettutinstallnunit" name="ccnettutinstallnunit"></a><span style="font-size:x-small;color:#993300;">3.3. Install Nunit</span></h4>
<p>For the sake of our example we will need <strong>Nunit</strong> so, if you haven&#8217;t already done, install it on the same machine on which you have installed CruiseControl.NET.</p>
<p>You can find the latest <a title="nunit home" href="http://www.nunit.org/" target="_blank">Nunit</a> release <a title="nunit download" href="http://sourceforge.net/project/showfiles.php?group_id=10749&amp;package_id=89482" target="_blank">here</a> at SourceForge.<br />
This article is based on the release 2.4.6, currently the latest. You can install it by downloading: <a title="nunit 2.4.6 msi" href="http://prdownloads.sourceforge.net/nunit/NUnit-2.4.6-net-2.0.msi?download" target="_blank">NUnit-2.4.6-net-2.0.msi</a>.</p>
<p>After the installation you will have a new directory under <em>%ProgramFiles% </em>: <span style="color:#808080;">C:\%ProgramFiles%\NUnit 2.4.6</span>.</p>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutinstallnunit"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettutconfiguration" name="ccnettutconfiguration"></a><span style="font-size:small;color:#993300;">4. CruiseControl.NET Server Configuration &#8211; General</span></h3>
<p>All the configuration files we&#8217;re going to talk about are placed or are to be placed in:<br />
<span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET\server</span>.</p>
<p>CruiseControl.NET comes with two server executables: <strong>ccservice.exe</strong> which is the windows service installed by the installation setup and <strong>ccnet.exe</strong> which is a console application included for testing purposes.<br />
It is much easier to debug a console application that a service so I strongly suggest to make your initial tests with ccnet.exe and carefully read the console output to get familiar with CCNet behavior.</p>
<p>Each of the two executables comes with a default configuration file (i.e.: <em>ccservice.exe.config</em> and <em>ccnet.exe.config</em>) that you don&#8217;t need to change at the moment.<br />
Moreover both the server processes (windows service or console application) look for a file named <strong>ccnet.config</strong> in which you will place all the actual information needed by CCNet to learn what it is supposed to do and how it is supposed to do it.</p>
<p><strong>ccnet.config</strong> is an xml file with a root element named <strong>&lt;cruisecontrol&gt;</strong> and a child element, named <strong>&lt;project&gt;</strong>, for each set of activities that we want CruiseControl.NET to execute, as shown in the following example:</p>
<pre class="brush: xml;">
&lt;cruisecontrol&gt;
&lt;project name=&quot;project1&quot;&gt;
    ...
  &lt;/project&gt;
&lt;project name=&quot;project2&quot;&gt;
    ...
  &lt;/project&gt;
&lt;/cruisecontrol&gt;
</pre>
<p>In this tutorial we will setup our CruiseControl.NET configuration with two logical sets of activities.<br />
For the sake of clarity we will benefit of the usage of xml entities.<br />
We&#8217;ll define each &#8216;project&#8217; configuration in a separate file and import all the files in &#8216;ccnet.config&#8217; by means of entity definitions and entity declarations:</p>
<pre class="brush: xml;">
&lt; !DOCTYPE cruisecontrol [
	&lt; !ENTITY project1 SYSTEM &quot;file:project1.xml.config&quot;&gt;
	&lt; !ENTITY project2 SYSTEM &quot;file:project2.xml.config&quot;&gt;
]&gt;
&lt;cruisecontrol&gt;
  &amp;project1;
  &amp;project2;
&lt;/cruisecontrol&gt;
</pre>
<p>Let&#8217;s focus, at first, only on the first project, so delete the second entity reference (i.e.: &amp;project2; ) thus obtaining:</p>
<pre class="brush: xml;">
&lt; !DOCTYPE cruisecontrol [
	&lt; !ENTITY project1 SYSTEM &quot;file:project1.xml.config&quot;&gt;
	&lt; !ENTITY project2 SYSTEM &quot;file:project2.xml.config&quot;&gt;
]&gt;
&lt;cruisecontrol&gt;
  &amp;project1;
&lt;/cruisecontrol&gt;
</pre>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutconfiguration"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettutprojectconfiguration" name="ccnettutprojectconfiguration"></a><span style="font-size:small;color:#993300;">5. Structure of a &#8216;Project&#8217; Configuration File</span></h3>
<p>What we need to do now is creating a file named: <strong>project1.xml.config</strong> in <span style="color:#808080;">C:\%ProgramFiles%\CruiseControl.NET\server</span><br />
and use it to setup CruiseControl.NET main activities.<br />
This file will contain what is called the &#8216;Project Configuration Block&#8217; for the first CCNet activity that we want to configure.<br />
First of all we need to assign a unique name to the root of the Project Configuration Block: the <strong>&lt;project&gt;</strong> tag.  We then write:</p>
<pre class="brush: xml;">
&lt;project name=&quot;1 - testProject&quot;&gt;
  &lt;webURL&gt;http://192.168.15.2:222&lt;/weburl&gt;
  &lt;workingDirectory&gt;C:\develop\CCnet\project1WorkingDir
  &lt;/workingDirectory&gt;
  &lt;artifactDirectory&gt;C:\develop\CCnet\project1CCnetArtifacts
  &lt;/artifactDirectory&gt;
  ...
&lt;/project&gt;
</pre>
<p>Let&#8217;s talk about the first three children nodes:</p>
<p><strong></strong> represents the URL at which the current project is available through the web interface. We will see later why it is useful.<br />
For now just make sure to set it to the IP of the server machine (in which you installed CCNet) and to the port that you chose for the WebDashboard website when you configured the web site in IIS (see: <a href="#ccnettutiiscreatesite">3.2. Create a CCNet Website in IIS</a>).</p>
<p><strong></strong> is the path to the main directory of this project and is meant to contain the checked out version of the project under integration<span style="color:#ff8433;">.</span><br />
This path will be accessible as an environment variable: <span style="color:#ff6600;">%CCNetWorkingDirectory%</span>, available to external scripts (we will see it later).<br />
I use to place all the projects managed with CCNET in folders under a common directory named: <span style="color:#808080;">C:\develop\CCnet</span>.<br />
For this test project I chose: <span style="color:#808080;">C:\develop\CCnet\project1WorkingDir</span>.</p>
<p>It is convenient to choose a directory in which to place all the stuff that will be used by CCNet (script files or executable files that you may want CruiseControl.NET to execute) as well as the <em>workingDirectory</em> in which CCNET will checkout the versioned files and the <em>artifactDirectory</em> in which it will output log files.<br />
In the example above I chose the directory: <span style="color:#808080;">C:\develop\CCnet</span> as the container of all CCNet related stuff.</p>
<p><strong></strong> is the path to the directory where all the build logs for this project will be placed.</p>
<p>Apart from the three tags described above, the main blocks that we&#8217;re going to add to the project configuration file are:</p>
<ul>
<li> <a href="#ccnettutsourcecontrolblock">Source Control Block</a></li>
<li> <a href="#ccnettuttriggerblock">Trigger Block</a></li>
<li> <a href="#ccnettutlabellerblock">Labeller Block</a></li>
<li> <a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettuttasksblock">9. Tasks Block</a></li>
<li> <a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutprebuildblock">13. PreBuild Block</a></li>
<li> <a href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/#ccnettutpublishersblock">12. Publishers Block</a></li>
</ul>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutprojectconfiguration"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettutsourcecontrolblock" name="ccnettutsourcecontrolblock"></a><span style="font-size:small;color:#993300;">6. Source Control Block</span></h3>
<p>Source Control configuration block tells CruiseControl.NET that the project named &#8216;1 &#8211; testProject&#8217; is bound to a Subversion repository.<br />
This means that the task performed when executing this project depends on the status of that particular Subversion repository.<br />
As soon as CruiseControl.NET detects a new revision in the repository it updates its working copy and executes the tasks related to the current project.<br />
Here is the xml excerpt:</p>
<pre class="brush: xml;">
&lt;sourcecontrol type=&quot;svn&quot;&gt;
&lt;trunkUrl&gt;svn://localhost/trunk&lt;/trunkUrl&gt;
  &lt;workingDirectory&gt;C:\develop\CCnet\project1WorkingDir
  &lt;/workingDirectory&gt;
  &lt;username&gt;ccnet &lt;/username&gt;
&lt;password&gt; ccnet &lt;/password&gt;
&lt;/sourcecontrol&gt;
</pre>
<p><strong></strong> contains the url of the repository that we want to check for modifications (e.g., <span style="color:#808080;">svn://svnserver/pathToRepo</span>).<br />
As we saw in the post <a title="subversion tutorial" href="http://ilmatte.wordpress.com/2008/04/27/guide-to-versioning-a-visual-studio-solution-with-subversion-tortoisesvn-and-ankhsvn/" target="_blank">Guide to Versioning a Visual Studio Solution with Subversion, TortoiseSVN and AnkhSVN</a>, Subversion could host several repositories under a common folder, say: <span style="color:#808080;">C:\develop\TestRepo</span>.<br />
But in that article, as well as in the current example, we set up only one repository and run svnserve with the command line: <strong>svnserve -d -r &#8220;C:\develop\test\repo&#8221;</strong>.<br />
So, specifying the server name (<em>localhost</em>) and the path to the particular repository we&#8217;re interested in, turns out to be simply: <span style="color:#808080;">svn://localhost/trunk</span> (instead of: <span style="color:#808080;">svn://localhost/SpecificRepositoryFolder/trunk</span>);<br />
<strong></strong> is the directory that will contain the working copy checked out by CCNET;<br />
<strong></strong> sets the timeout for the source control operation. It defaults to 10 minutes and you can set it to a different amount of time in milliseconds (default) or specifying units (&#8220;millis&#8221;, &#8220;seconds&#8221;, &#8220;minutes&#8221;, &#8220;hours&#8221;); I left it out thus accepting the default.<br />
If you want to set it to a different value remember to <strong><span style="text-decoration:underline;">not</span> choose a too short timeout value</strong> because if the timeout is exceeded the build will fail without providing information about the reason.<br />
In that case the only way you can retrieve the actual reason of the build failing is by analyzing CCNET log file in the <span style="color:#808080;">CruiseControl.NET\server</span> folder (if you set log4net to the debug log level)<br />
<strong></strong> and <strong></strong> must be set to a valid svn account that CCNET can use to access Subversion repository.</p>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutsourcecontrolblock"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettuttriggerblock" name="ccnettuttriggerblock"></a><span style="font-size:small;color:#993300;">7. Trigger Block</span></h3>
<p>A trigger block is needed to specify when CruiseControl.NET will start a new integration cycle.<br />
We want to check for the repository status continuously so we need an &#8216;Interval Trigger&#8217; to tell CruiseControl.NET to perform integration periodically after a specified amount of time:</p>
<pre class="brush: xml;">
&lt;triggers&gt;
  &lt;intervalTrigger name=&quot;Subversion&quot; seconds=&quot;10&quot; /&gt;
&lt;/triggers&gt;
</pre>
<p>CruiseControl.NET, as far as project &#8216;1 &#8211; TestProject&#8217; is concerned, polls the repository every 10 seconds to see if any changes has been committed.<br />
The <span style="color:#ff9900;"><em>name</em> </span>attribute is used by CruiseControl.NET GUI to identify the trigger that requested the build;<br />
The <span style="color:#ff9900;"><em>seconds</em> </span>attribute is the amount of time before triggering the next integration cycle.</p>
<p>Each time the time interval elapses, CCNET checks for modifications and, by default, runs integration only if changes are detected.</p>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettuttriggerblock"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<h3><a title="ccnettutlabellerblock" name="ccnettutlabellerblock"></a><span style="font-size:small;color:#993300;">8. Labeller Block</span></h3>
<p>A label is created, at each integration cycle, to identify the specific build occurred.<br />
Different labellers can be used to generate the label that CCNet will use to track the builds.</p>
<p>Other than the <em>Labeller Blocks</em> that come with the CruiseControl.NET distribution, many people provided plugin <em>Labeller Blocks</em> to target the generation of labels with specific formats.</p>
<p>A very good one, IMHO, is SvnRevisionLabeller by David Keaveny (much important to me because I recently contributed to the project).<br />
This plugin allows labelling CruiseControl.NET builds with Subversion&#8217;s repository revision numbers and I think this is a really useful feature.<br />
So this example will use SvnRevisionLabeller as the Labeller Block.<br />
For detailed information about this plugin see my post: <a title="svn revision labeller" href="http://ilmatte.wordpress.com/2008/03/05/cruisecontrolnet-and-subversion-svnrevisionlabeller/" target="_blank">CruiseControl.NET and Subversion &#8211; SvnRevisionLabeller</a>.</p>
<p>To use the SvnRevisionLabeller plugin in your installation of CruiseControl.NET you need to unzip the downloaded package and copy the assembly: <strong>ccnet.SvnRevisionLabeller.plugin.dll</strong> in the <em>server</em> folder directory under the CruiseControl.NET install path (e.g.: &#8216;C:\Program Files\CruiseControl.NET\server&#8217;).</p>
<p>Next you need to configure the <strong>Labeller Block</strong> in your project:</p>
<pre class="brush: xml;">
&lt;labeller type=&quot;svnRevisionLabeller&quot;&gt;
	&lt;major&gt;7&lt;/major&gt;
	&lt;minor&gt;11&lt;/minor&gt;
	&lt;url&gt;svn://localhost/trunk&lt;/url&gt;
&lt;/labeller&gt;
</pre>
<p>SvnRevisionLabeller will produce build labels in the format:</p>
<p><strong>major.minor.svnRevision.build</strong></p>
<p>where <strong>major</strong> and <strong>minor</strong> are the two values you set in the configuration block while <strong>svnRevision</strong> is the current version in the Subversion&#8217;s repository related to this project.<br />
The <strong>build</strong> number is automatically incremented each time a new build is forced if no further modification has been committed to the repository.</p>
<p><strong>&lt;url&gt;</strong> is the path to the repository used to retrieve the revision number (e.g. <span style="color:#808080;">svn://svnserver/pathToRepo/trunk</span>). Actually it should be filled with the same path used in the <strong>&lt;trunkUrl&gt;</strong> field of the Subversion <strong>Source Control Block</strong>.<br />
In our example it is:</p>
<pre class="brush: xml;">
&lt;url&gt;svn://localhost/trunk&lt;/url&gt;
</pre>
<p>Following is a configuration for <strong>SvnRevisionLabeller</strong> with the complete set of fields:</p>
<pre class="brush: xml;">
&lt;labeller type=&quot;svnRevisionLabeller&quot;&gt;
&lt;prefix&gt;Test-&lt;/prefix&gt;
  &lt;major&gt;7&lt;/major&gt;
  &lt;minor&gt;11&lt;/minor&gt;
  &lt;url&gt;svn://localhost/trunk&lt;/url&gt;
  &lt;username&gt;ccnet&lt;/username&gt;
&lt;password&gt;ccnet&lt;/password&gt;
&lt;/labeller&gt;
</pre>
<p>Such a configuration will produce a label with the following format: <strong>Test-major.minor.svnRevision.build</strong>.<br />
<strong>&lt;username&gt;</strong> and <strong>&lt;password&gt;</strong> are the username and password of a valid Subversion account for the repository specified in the <strong>&lt;url&gt;</strong> field.</p>
<p>You can use in an external script the build label produced, which is stored in an environment variable.<br />
It can be useful to flag release version of output dlls.<br />
You can access the build number from a script with the syntax: <span style="color:#ff6600;">%CCNetLabel%</span> or from a C# application with the following row:</p>
<pre class="brush: csharp;">
Environment.GetEnvironmentVariable(&quot;ccnetlabel&quot;);
</pre>
<p>If you used the SolutionInfo approach in your Visual Studio solution (see my post: <a title="solutioninfo" href="http://ilmatte.wordpress.com/2008/02/10/solutioninfo-and-partitioned-single-solution/#introductionsolutioninfo1" target="_blank">SolutionInfo and Partitioned Single Solution</a>) you can use the build label produced by <strong>SvnRevisionLabeller</strong> to update the <strong>AssemblyFileVersion</strong> attribute in the SolutionInfo.cs file.<br />
In this way you can provide consistent versioning of the released assemblies together with easy trackability of the corresponding source code&#8217;s revision.</p>
<p>Be careful not to use the &lt;prefix&gt; tag in this case because you need to set <strong>AssemblyFileVersion</strong> to a string in the format:<br />
<strong>major.minor.svnRevision.build</strong><br />
with all of the 4 fields being numerical values.</p>
<p><a href="#ccnettut1top"><span style="font-size:80%;color:red;">→ top of post</span></a><br />
<a href="#ccnettutlabellerblock"><span style="font-size:80%;color:red;">→ top of paragraph</span></a></p>
<p><span style="position:relative;left:50px;"><a title="tutorial part 2" href="http://ilmatte.wordpress.com/2008/06/15/cruisecontrolnet-tutorial-part-2/" target="_self">CruiseControl.Net Tutorial &#8211; Part 2 &gt;&gt;</a></span></p>
<p><a href="#ccnettutlabellerblock"></a><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filmatte.wordpress.com%2f2008%2f06%2f01%2fcruisecontrolnet-tutorial-part-1%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filmatte.wordpress.com%2f2008%2f06%2f01%2fcruisecontrolnet-tutorial-part-1%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ilmatte.wordpress.com/50/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ilmatte.wordpress.com/50/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilmatte.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilmatte.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilmatte.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilmatte.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilmatte.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilmatte.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilmatte.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilmatte.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilmatte.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilmatte.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=50&subd=ilmatte&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3cb2e7cb9a15640aab9ac6639d9bc462?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filmatte.wordpress.com%2f2008%2f06%2f01%2fcruisecontrolnet-tutorial-part-1%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>CruiseControl.NET and Subversion &#8211; SvnRevisionLabeller</title>
		<link>http://ilmatte.wordpress.com/2008/03/05/cruisecontrolnet-and-subversion-svnrevisionlabeller/</link>
		<comments>http://ilmatte.wordpress.com/2008/03/05/cruisecontrolnet-and-subversion-svnrevisionlabeller/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 16:05:44 +0000</pubDate>
		<dc:creator>ilmatte</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[CruiseControl.NET]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[Build Labeller]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=48</guid>
		<description><![CDATA[
1. Download
2. Description
3. Usage
3.1. Build Labels
3.2. Installation
3.3. Configuration
1. Download
I recently contributed to a project that I find very useful:
SvnRevisionLabeller (direct download link) plugin for CruiseControl.NET by David Keaveny.
You can also find it having a look at the Contributions Page in the CruiseControl.Net official website (it&#8217;s the third item under the title: Labeller Blocks).
→ top of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=48&subd=ilmatte&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a name="svnrevlabeltop" title="svnrevlabeltop"></a><br />
<a href="#downloadsvnrevlabel">1. Download</a><br />
<a href="#descriptionsvnrevlabel">2. Description</a><br />
<a href="#usagesvnrevlabel">3. Usage</a><br />
<span style="position:relative;left:10px;"><a href="#labelsvnrevlabel">3.1. Build Labels</a></span><br />
<span style="position:relative;left:10px;"><a href="#installsvnrevlabel">3.2. Installation</a></span><br />
<span style="position:relative;left:10px;"><a href="#configsvnrevlabel">3.3. Configuration</a></span></p>
<h3><a name="downloadsvnrevlabel" title="downloadsvnrevlabel"></a><font color="#993300" size="3">1. Download</font></h3>
<p>I recently contributed to a project that I find very useful:</p>
<p>SvnRevisionLabeller (<a href="http://code.google.com/p/svnrevisionlabeller/" title="svnrevisionlabellerzip" target="_blank">direct download link</a>) plugin for CruiseControl.NET by <a href="http://davidkeaveny.blogspot.com/" title="davidblog" target="_blank">David Keaveny</a>.<br />
You can also find it having a look at the <a href="http://confluence.public.thoughtworks.org/display/CCNETCOMM/Contributions" title="contributionsccnet" target="_blank">Contributions Page</a> in the CruiseControl.Net <a href="http://confluence.public.thoughtworks.org/display/CCNET" title="ccnetwebsite" target="_blank">official website</a> (it&#8217;s the third item under the title: <font color="#333399">Labeller Blocks</font>).</p>
<p><a href="#downloadsvnrevlabel"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#svnrevlabeltop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a name="descriptionsvnrevlabel" title="descriptionsvnrevlabel"></a><font color="#993300" size="3">2. Description</font></h3>
<p>David Keaveny&#8217;s SvnRevisionLabeller lets CruiseControl.NET generate build labels based upon Subversion&#8217;s repository revision number.</p>
<p>I contributed to the project with a bug fix and by adding support for secure access to a Subversion repository (connecting with a repository&#8217;s particular account: username and password).</p>
<p>A file named Readme.txt comes zipped with the distribution.<br />
Inside that file you can find instructions about how to install and configure SvnRevisionLabeller as the <font color="#000080">Labeller Block</font> of choice in your CCnet configuration file.</p>
<p>In this article I will try to briefly guide you through these steps.</p>
<p><a href="#descriptionsvnrevlabel"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#svnrevlabeltop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a name="usagesvnrevlabel" title="usagesvnrevlabel"></a><font color="#993300" size="3">3. Usage</font></h3>
<p>Let&#8217;s have a look at how to setup CruiseControl.NET server to work with the SvnRevisionLabeller plugin.</p>
<h4><a name="labelsvnrevlabel" title="labelsvnrevlabel"></a><font color="#993300" size="2">3.1. Build Labels</font></h4>
<p>SvnRevisionLabeller produces build labels in the format:</p>
<p><i>major.minor.svnRevision.build</i></p>
<p><i>major</i> and <i>minor</i> numbers are set in the configuration of the <font color="#333399">Labeller Block</font>,<br />
<i>svnRevision</i> number is retrieved from the Subversion repository,<br />
<i>build</i> is automatically incremented if a new build is forced when no further modification to the repository happened.</p>
<p>The label produced by whichever <font color="#000080">Labeller Block</font> is made available to the <font color="#000080">Task Blocks</font> by means of the environment variable: <font color="#ff6600">CCNetLabel</font>.<br />
That environment variable can then be accessed by NAnt or MSBuild (as <font color="#ff6600">${CCNetLabel}</font> or <font color="#ff6600">$(CCNetLabel</font><font color="#ff6600">)</font>) or by an External script with the usual syntax for environment variables on Windows Operating Systems: <font color="#ff6600">%CCNetLabel%</font>.</p>
<h4><a name="installsvnrevlabel" title="installsvnrevlabel"></a><font color="#993300" size="2">3.2. Installation</font></h4>
<p>Installing the SvnRevisionLabeller plugin is just a matter of unzipping the package (ccnet.SvnRevisionLabeller.plugin.zip) into a temporary directory and of copying the assembly:<br />
<font color="#808080">src\ccnet.SvnRevisionLabeller.plugin\bin\Release\ccnet.SvnRevisionLabeller.plugin.dll</font></p>
<p>that you find inside the temporary directory into the directory in which CruiseControl.NET has been installed (e.g.: <font color="#808080">C:\Program Files\CruiseControl.NET\server</font>).</p>
<p>Next you need to configure the <font color="#333399">Labeller Block</font> in your projects in order to let them use SvnRevisionLabeller.<br />
Let&#8217;s see how.</p>
<h4><a name="configsvnrevlabel" title="configsvnrevlabel"></a><font color="#993300" size="2">3.3. Configuration</font></h4>
<p>Following is the basic configuration for SvnRevisionLabeller. Only the required fields are set:</p>
<pre class="brush: xml;">
&lt;labeller type=&quot;svnRevisionLabeller&quot;&gt;
  &lt;major&gt;7&lt;/major&gt;
  &lt;minor&gt;11&lt;/minor&gt;
  &lt;url&gt;svn://localhost/repository/trunk&lt;/url&gt;
&lt;/labeller&gt;</pre>
<p>where:&lt;major&gt; and &lt;minor&gt; are the first two numbers in the build label:<br />
<font color="#333399"> 7.11.svnRevision.build</font><br />
and &lt;url&gt; represents the path to the repository monitored by the current CruiseControl.net project. Actually the &lt;url&gt; field must be filled with the same path used in the &lt;trunkurl&gt; field of the Subversion <font color="#000080">Source Control Block</font>:</p>
<pre class="brush: xml;">
&lt;sourcecontrol type=&quot;svn&quot;&gt;
  &lt;trunkurl&gt;svn://localhost/repository/trunk&lt;/trunkurl&gt;
  ...
&lt;/sourcecontrol&gt;</pre>
<p>Following is a configuration for the SvnRevisionLabeller with the complete set of fields:</p>
<pre class="brush: xml;">
&lt;labeller type=&quot;svnRevisionLabeller&quot;&gt;
  &lt;prefix&gt;Test-&lt;/prefix&gt;
  &lt;major&gt;7&lt;/major&gt;
  &lt;minor&gt;11&lt;/minor&gt;
  &lt;url&gt;svn://localhost/repository/trunk&lt;/url&gt;
  &lt;username&gt;ccnetuser&lt;/username&gt;
  &lt;password&gt;ccnetpassword&lt;/password&gt;
&lt;/labeller&gt;</pre>
<p>where:&lt;prefix&gt; is a prefix added to the build label in the format:<br />
<font color="#000080">Test-major.minor.svnRevision.build</font><br />
&lt;username&gt; and &lt;password&gt; are the username and password of a valid Subversion account for the repository specified in the &lt;url&gt; field.<br />
<u> You&#8217;d better</u> create a specific account used only by CruiseControl.NET.That&#8217;s it! In this way CruiseControl.NET will flag its builds with the revision number from Subversion and you can retrieve such value if you want to use it to modify the AssemblyInfo.cs files in your Visual Studio projects or if you want to flag your administrative backup names. </p>
<p>
<a href="#usagesvnrevlabel"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#svnrevlabeltop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ilmatte.wordpress.com/48/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ilmatte.wordpress.com/48/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilmatte.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilmatte.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilmatte.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilmatte.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilmatte.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilmatte.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilmatte.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilmatte.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilmatte.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilmatte.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=48&subd=ilmatte&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ilmatte.wordpress.com/2008/03/05/cruisecontrolnet-and-subversion-svnrevisionlabeller/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3cb2e7cb9a15640aab9ac6639d9bc462?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
		<item>
		<title>SolutionInfo and Partitioned Single Solution</title>
		<link>http://ilmatte.wordpress.com/2008/02/10/solutioninfo-and-partitioned-single-solution/</link>
		<comments>http://ilmatte.wordpress.com/2008/02/10/solutioninfo-and-partitioned-single-solution/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 13:07:44 +0000</pubDate>
		<dc:creator>ilmatte</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Project Management]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[SolutionInfo]]></category>
		<category><![CDATA[Structuring Solutions]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=25</guid>
		<description><![CDATA[
1. Prerequisites
2. Introduction &#8211; SolutionInfo.cs
3. Introduction &#8211; Partitioned single solution
4. Partitioned single solution and SolutionInfo.cs &#8211; The problem
5. Partitioned single solution and SolutionInfo.cs &#8211; The Solution
6. Subversion Issue 695 and Release 1.5
7. Notes
7.1. Add a file as link
7.2. Set Build Action to None
In this article I will talk about possible issues when creating a SolutionInfo.cs [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=25&subd=ilmatte&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a name="solutioninfotop" title="solutioninfotop"></a><br />
<a href="#prerequisitessolutioninfo">1. Prerequisites</a><br />
<a href="#introductionsolutioninfo1">2. Introduction &#8211; SolutionInfo.cs</a><br />
<a href="#introductionsolutioninfo2">3. Introduction &#8211; Partitioned single solution</a><br />
<a href="#problemsolutioninfo">4. Partitioned single solution and SolutionInfo.cs &#8211; The problem</a><br />
<a href="#thesolutionsolutioninfo">5. Partitioned single solution and SolutionInfo.cs &#8211; The Solution</a><br />
<a href="#subversionsolutioninfo">6. Subversion Issue 695 and Release 1.5</a><br />
<a href="#notessolutioninfo">7. Notes</a><br />
<span style="position:relative;left:10px;"><a href="#solutioninfonote1">7.1. Add a file as link</a></span><br />
<span style="position:relative;left:10px;"><a href="#solutioninfonote2">7.2. Set Build Action to None</a></span></p>
<p>In this article I will talk about possible issues when creating a SolutionInfo.cs file<br />
while using the Partitioned single solution development model.</p>
<h3><a name="prerequisitessolutioninfo" title="prerequisitessolutioninfo"></a><font color="#993300" size="3">1. Prerequisites</font></h3>
<p>While writing this article I was using the following software:</p>
<p>Visual Studio 2005<br />
<a href="http://subversion.tigris.org/" title="Subversion Home Page" target="_blank">Subversion</a> (<a href="http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91" title="Download page" target="_blank">Download the latest version</a>)</p>
<h3><a name="introductionsolutioninfo1" title="introductionsolutioninfo1"></a><font color="#993300" size="3">2. Introduction &#8211; SolutionInfo.cs</font></h3>
<p>Having multiple projects in a solution means having multiple assemblies, and having multiple assemblies could mean that you want to deploy them as separate assemblies.<br />
Each project generated by <b>Visual Studio 2005</b> contains, by default, an <i>AssemblyInfo.cs</i> file in which you can write assembly attributes.<br />
If you open <i>AssemblyInfo.cs</i> you will find a set of assembly attributes with default values.<br />
The values for some of these attributes could vary from project to project but others (such as <i>AssemblyVersion</i>) should be application wide.<br />
For this purpose a common choice is the <i>SolutionInfo.cs</i> pattern as illustrated by Juval Lowy (you can find his book: <a href="http://www.amazon.com/gp/product/0596102070?ie=UTF8&amp;tag=myvionc-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596102070">Programming .NET Components, 2nd Edition</a><img src="http://www.assoc-amazon.com/e/ir?t=myvionc-20&amp;l=as2&amp;o=1&amp;a=0596102070" style="border:medium none !important;margin:0 !important;" border="0" height="1" width="1" /> at Amazon).<br />
It consists in grouping all the attributes common to all projects (solution wide attributes) in a separate file named <i>SolutionInfo.cs</i> that will be included as a solution item.<br />
Each project will contain, under the Properties directory, an <i>AssemblyInfo.cs</i> file and a link to the shared <i>SolutionInfo.cs</i> file (see note: <a href="#solutioninfonote1">Add file as link</a>).<br />
Adding that file as a link allows you to modify always the same file, no matter which link you open so having all the projects&#8217; properties updated at once.<br />
This approach is very useful for incrementing Version Number.</p>
<p><a href="#introductionsolutioninfo1"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#solutioninfotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a name="introductionsolutioninfo2" title="introductionsolutioninfo2"></a><font color="#993300" size="3">3. Introduction &#8211; Partitioned single solution</font></h3>
<p><b>References:</b></p>
<p><a href="http://msdn2.microsoft.com/en-us/library/ms998208.aspx" title="Structuring Solutions and Projects" target="_blank">Structuring Solutions and Projects (MSDN Article)</a><br />
or you can find an updated version of the preceding article in the book:<br />
&#8216;<i>Team development with visual studio team foundation server</i>&#8216;<br />
that you can freely download at: <a href="http://www.codeplex.com/TFSGuide" title="TFSGuide" target="_blank">http://www.codeplex.com/TFSGuide</a></p>
<p><b>Partitioned Single Solution:</b></p>
<p>As shown in the articles above, when you have a big application and want to allow developers to work on smaller portions of the appliction, you can consider using the &#8216;<i>partitioned single solution</i>&#8216; development model.<br />
It consists in creating a top solution containing all the projects in the application and then introducing separate solution files for subsets of related projects.<br />
Each solution file will contain all the projects a develper needs to work on and all the referenced projects.<br />
In this way it is possible to checkout only the projects actually needed on each developer&#8217;s workstation, thus obtaining a lighter build process during the development stage.</p>
<p>This approach requires additional work and time to keep all the solution files aligned but it provides a safer way to share work on the same application between different developers.</p>
<p><a href="#introductionsolutioninfo2"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#solutioninfotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a name="problemsolutioninfo" title="problemsolutioninfo"></a><font color="#993300" size="3">4. Partitioned single solution and SolutionInfo.cs &#8211; The problem</font></h3>
<p>This article aims to point out that there are a couple of drawbacks in combining the SolutionInfo pattern with the Partitioned single solution model.</p>
<p><b>Case Scenario 1:</b></p>
<p>First of all the SolutionInfo approach makes it impossible for a developer to copy the project as is to another location and import it into another solution file.<br />
At compile time he would get the following message:</p>
<p><font color="#ff0000">&#8216;Error	1	Source file &#8216;pathToSolution\SolutionInfo.cs&#8217; could not be opened &#8230;&#8217;</font></p>
<p>He will have to create a <i>SolutionInfo.cs</i> file in the same directory in which the copy of the project is placed in order to make the build succeed.</p>
<p>To understand why this fixes the problem let&#8217;s have a look at what happens behind the scenes:</p>
<p>Say that we created projects leaving the Visual Studio default behavior unchanged, that is, they are located in subdirectories of the directory containing the solution file.<br />
When we add a file as link to a project (<a href="#solutioninfonote1">see note</a>), the following lines will be added to the project file (<i>projectName.csproj</i>) under the &#8216;<b>ItemGroup</b>&#8216; tag:</p>
<pre class="brush: xml;">
&lt;compile Include=&quot;..\SolutionInfo.cs&quot;&gt;
    &lt;link&gt;Properties\SolutionInfo.cs&lt;/link&gt;
&lt;/compile&gt;</pre>
<p>The &#8216;<b>Include</b>&#8216; attribute stores the path to the original file that we&#8217;re linking to.<br />
The &#8216;<b>Link</b>&#8216; tag stores the path in which the link will be shown in Solution Explorer (including possible solution directory e.g.: &#8216;<i>Properties</i>&#8216;).<br />
As you can see, the &#8216;<b>Include</b>&#8216; attribute stores the <u>relative</u> path to <i>SolutionInfo.cs</i> with respect to the <i>projectName.csproj</i> file location. This will end up in Visual Studio (and MSbuild) looking for a file named <i>SolutionInfo.cs</i> one level above with respect to the <i>projectName.csproj</i> file.So this is the reason for the error message shown above if copying a project directory anywhere else.Let&#8217;s go further and introduce the SolutionInfo method in a Partitioned Single Solution.The default Visual Studio behaviour of introducing relative paths (instead of using paths relative to the solution path) makes linking a file (e.g.: <i>SolutionInfo.cs</i>) in a Partitioned Single Solution structure an error prone procedure.<br />
In fact it can easily lead to the build error reported above, if we use nested directory structures.<br />
Let&#8217;s have a look at the possible situations:</p>
<div><b>Case Scenario 2:</b></div>
<p>We could decide to create a directory structure as shown in the following picture:<img src="http://ilmatte.files.wordpress.com/2008/02/case1.jpg" alt="PartitionedSolutionStructure1" /></p>
<div>If we place all the solution files in the top directory, as shown above, we won&#8217;t have any problem.<br />
In fact when a developer checks out the directory containing the solution file he needs, he will also get the <i>SolutionInfo.cs</i> file (remember that with Subversion you can only checkout directories).<br />
Practically speaking we will always checkout the top directory, no matter which solution file we will use.</div>
<p><b>Case Scenario 3:</b></p>
<p>What if we want to add a solution file for each project and we want to place it in the  project&#8217;s directory?</p>
<p><img src="http://ilmatte.files.wordpress.com/2008/02/case2.jpg" alt="PartitionedSolutionStructure2" /></p>
<p>A developer could checkout from the repository only a project&#8217;s directory and he would get the solution file too.<br />
But when he will try to build the solution he will get the file missing error!<br />
If he provides a copy of <i>SolutionInfo.cs</i> in the solution&#8217;s directory (which is the project&#8217;s directory too) it won&#8217;t work because MSbuild (as we said before) looks for the file up one level (..\<i>SolutionInfo.cs</i>).<br />
The developer should create a <i>SolutionInfo.cs</i> file outside of its working copy to make the build succeed.If we have a more complicated directory structure with different levels of directories, with project directories in some of this levels, and with solution files in some of these levels too, the situation is even worse.<br />
In fact the <i>SolutionInfo.cs</i> file is located more than one level up with respect to some of this project and solution files as you can see in the following image:</p>
<p><b></b><img src="http://ilmatte.files.wordpress.com/2008/02/case3.jpg" alt="PartitionedSolutionStructure3" /></p>
<p>Each time a developer checks out a solution directory that is not the root one he will miss the <i>SolutionInfo.cs</i> file and he&#8217;ll need to open a project file in a text editor to know were it is supposed to be.</p>
<p><a href="#problemsolutioninfo"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#solutioninfotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a name="thesolutionsolutioninfo" title="thesolutionsolutioninfo"></a><font color="#993300" size="3">5. Partitioned single solution and SolutionInfo.cs &#8211; The Solution</font></h3>
<p>In order to avoid uncertainty about where each project expects the <i>SolutionInfo.cs</i> to be placed, we need to reference it with a path relative to the solution location instead of the project&#8217;s directory. So we can open <i>projectName.csproj</i> in a text editor and modify the entry as follows:</p>
<p><b>SolutionDir variable</b></p>
<pre class="brush: xml;">
&lt;compile Include=&quot;$(SolutionDir)\SolutionInfo.cs&quot;&gt;
    &lt;link&gt;Properties\SolutionInfo.cs&lt;/link&gt;
&lt;/compile&gt;</pre>
<p>In this way we let the projects be independent of their location in the directory structure.Let&#8217;s go one step further.<br />
If a developer doesn&#8217;t want to provide a <i>SolutionInfo.cs</i> file to its custom solution his solution won&#8217;t compile unless he sets <i>SolutionInfo.cs</i> &#8216;<b>Build Action</b>&#8216; to &#8216;<b>None</b>&#8216; (see note: <a href="#solutioninfonote2">Set Build Action to None</a>).<br />
The problem here is that the &#8216;<b>Build Action</b>&#8216; of a file is stored in the versioned <i>projectName.csproj</i> file. Changing this setting will impact on the working copies of all developers using that same project and even on the release build script.<br />
Luckily we can apply a work around to this problem:</p>
<div><b>The Condition attribute</b></div>
<p>the &#8216;<b>Compile</b>&#8216; tag in the <i>projectName.csproj</i> file supports another useful attribute: &#8216;<b>Condition</b>&#8216;.<br />
The condition specified by such attribute will be evaluated by MSBuild during the build process and the file will be compiled only if the condition is satisfied.<br />
We could add it to the row related to <i>SolutionInfo.cs</i> thus obtaining:</p>
<pre class="brush: xml;">
&lt;compile Include=&quot;$(SolutionDir)\SolutionInfo.cs&quot;
        Condition=&quot;Exists('$(SolutionDir)\SolutionInfo.cs')&quot;&gt;
    &lt;link&gt;Properties\SolutionInfo.cs&lt;/link&gt;
&lt;/compile&gt;</pre>
<p>MSBuild will evaluate the condition and if it will not find the linked file in the specified path it won&#8217;t even try to compile it.<br />
This will allow developers to always have their projects successfully built even if a <i>SolutionInfo.cs</i> file is not present on disk.<br />
Solution Explorer will let the project build succeed but will show a broken link in the GUI to let the user know that something is missing.The assembly resulting from such a working copy build process will lack the solution wide assembly information but the continuous integration tools, as well as developers using solutions including a <i>SolutionInfo.cs</i> file, will have their projects build with the complete assembly information.</p>
<div><a href="#thesolutionsolutioninfo"><span style="font-size:80%;color:red;"></span></a><a href="#thesolutionsolutioninfo"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#solutioninfotop"><span style="font-size:80%;color:red;">→ top of post</span></a></div>
<h3><a name="subversionsolutioninfo" title="subversionsolutioninfo"></a><font color="#993300" size="3">6. Subversion Issue 695 and Release 1.5</font></h3>
<p>If you use Subversions as Version Control System you must be aware of a problem in which you may run into when working with a partitioned single solution model.<br />
If you organize your repository, say, like in the case scenario 2, and you want to checkout a solution (not the global one) and only the projects (and projects&#8217; directories) referenced by that solution you should do it in two separate steps:</p>
<p>first of all keep in mind that with Subversion you can only checkout directories, so you cannot have only the solution file you need but you&#8217;re forced to get in your working copy all the solution files defined in the root directory:</p>
<p>- checkout non-recursively the root directory (the one with the solution files),</p>
<p>next you can add to your working copy only the projects&#8217; directories you want:</p>
<p>- call svn update separately specifying the subdirectories you need.</p>
<p>This will seem to work at first but it is not true.<br />
There&#8217;s an old implementation issue in Subversion (see: <a href="http://subversion.tigris.org/issues/show_bug.cgi?id=695" title="issue695" target="_blank">issue 695</a>), related to checking out a directory non-recursively :</p>
<p>the issue consists in the fact that such a directory in the working-copy is not aware of being a partial checkout. So as long as anyone works on identical working copies everything works fine otherwise you will obtain a weird behavior.<br />
If someone commits changes to, say, a directory that you didn&#8217;t check out from the repository, the first time you will make a global update of your working copy you&#8217;ll get the following error message:</p>
<p>&gt;&gt; <font color="#ff0000">Error: Directory &#8216;pathToWorkingCopy\project3Dir&#8217; is missing</font><br />
&gt;&gt; <font color="#ff0000">Error: Please execute the &#8220;Cleanup&#8221; command.</font></p>
<p>If you execute the cleanup and try to update again, the whole root directory will be checked out in your working copy!</p>
<p>The bug has been fixed and sparse directory checkout should be allowed with the upcoming 1.5 version of Subversion.<br />
At the moment if you want to be safe with your working copy you have to checkout the whole root directory.</p>
<p><a href="#subversionsolutioninfo"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#solutioninfotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a name="notessolutioninfo" title="notessolutioninfo"></a><font color="#993300" size="3">7. Notes</font></h3>
<p><span style="position:relative;left:10px;"><a href="#solutioninfonote1">7.1. Add file as link</a></span><br />
<span style="position:relative;left:10px;"><a href="#solutioninfonote2">7.2. Set Build Action to None</a></span></p>
<h4><a name="solutioninfonote1" title="solutioninfonote1"></a><font color="#993300" size="2">7.1. Add file as link</font></h4>
<p>When you want to add a file as link to a project simply right click on the project and choose<i> Add &#8211;&gt; Existing item</i>.<br />
In the choose file dialog box locate and select the file you want (say e.g. <i>SolutionInfo.cs</i>). Don&#8217;t click the Add button, you should click the little down arrow on the right edge of the Add button instead. A drop down menu will appear as shown in the picture. Choose Add as link and you&#8217;re done (then you can move the link anywhere else in the project directory structure simply dragging it in Solution Explorer).</p>
<p><img src="http://ilmatte.files.wordpress.com/2008/02/addlink2.jpg" alt="Add As Link" /></p>
<p><a href="#notessolutioninfo"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#solutioninfotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h4><a name="solutioninfonote2" title="solutioninfonote2"></a><font color="#993300" size="2">7.2. Set Build Action to None</font></h4>
<p>To set the Build Action to None for a project item simply select the item in Solution Explorer (e.g.: <i>SolutionInfo.cs</i>) and look at the Properties Panel.<br />
A bunch of properties will be shown for the selected item through which you will see: &#8216;<b>Build Action</b>&#8216; with the value &#8216;<b>Compile</b>&#8216;. Just click on the value and a drop down list will appear as shown in the picture. Select &#8216;<b>None</b>&#8216; and you&#8217;re done.</p>
<p><img src="http://ilmatte.files.wordpress.com/2008/02/buildactionnone.jpg" alt="BuildActionNone" /></p>
<p><a href="#notessolutioninfo"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#solutioninfotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ilmatte.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ilmatte.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilmatte.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilmatte.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilmatte.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilmatte.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilmatte.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilmatte.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilmatte.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilmatte.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilmatte.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilmatte.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=25&subd=ilmatte&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ilmatte.wordpress.com/2008/02/10/solutioninfo-and-partitioned-single-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3cb2e7cb9a15640aab9ac6639d9bc462?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>

		<media:content url="http://www.assoc-amazon.com/e/ir?t=myvionc-20&#38;l=as2&#38;o=1&#38;a=0596102070" medium="image" />

		<media:content url="http://ilmatte.files.wordpress.com/2008/02/case1.jpg" medium="image">
			<media:title type="html">PartitionedSolutionStructure1</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/02/case2.jpg" medium="image">
			<media:title type="html">PartitionedSolutionStructure2</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/02/case3.jpg" medium="image">
			<media:title type="html">PartitionedSolutionStructure3</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/02/addlink2.jpg" medium="image">
			<media:title type="html">Add As Link</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/02/buildactionnone.jpg" medium="image">
			<media:title type="html">BuildActionNone</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio Nunit &amp; Rhino Mocks Templates</title>
		<link>http://ilmatte.wordpress.com/2008/01/15/visual-studio-nunit-rhinomocks-templates/</link>
		<comments>http://ilmatte.wordpress.com/2008/01/15/visual-studio-nunit-rhinomocks-templates/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 09:11:05 +0000</pubDate>
		<dc:creator>ilmatte</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[RhinoMocks]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[code snippets]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[Nunit]]></category>
		<category><![CDATA[Project Templates]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Template]]></category>
		<category><![CDATA[Test driven development]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://ilmatte.wordpress.com/2008/01/15/visual-studio-nunitrhinomocks-templates/</guid>
		<description><![CDATA[
1. Introduction
2. System Requirements
3. Download and Install
4. Package Contents
4.1. Test Class Library Project Template
4.2. Test Class ItemTemplate
4.3. Code Snippets
5. Uninstall
6. Suggested Books
1. Introduction
If you&#8217;ve been using &#8216;NUnit&#8217; you found yourself involved in doing repetitive actions like creating test projects and adding test classes and test methods.
If you ever had a try with the &#8216;Rhino Mocks&#8217; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=9&subd=ilmatte&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a title="rhinotop" name="rhinotop"></a><br />
<a href="#introductionrhino">1. Introduction</a><br />
<a href="#requirementsrhino">2. System Requirements</a><br />
<a href="#downloadrhino">3. Download and Install</a><br />
<a href="#contentsrhino">4. Package Contents</a><br />
<span style="position:relative;left:10px;"><a href="#contents1rhino">4.1. Test Class Library Project Template</a></span><br />
<span style="position:relative;left:10px;"><a href="#contents2rhino">4.2. Test Class ItemTemplate</a></span><br />
<span style="position:relative;left:10px;"><a href="#contents3rhino">4.3. Code Snippets</a></span><br />
<a href="#uninstallrhino">5. Uninstall</a><br />
<a href="#booksrhino">6. Suggested Books</a></p>
<h3><a title="introductionrhino" name="introductionrhino"></a><span style="font-size:small;color:#993300;">1. Introduction</span></h3>
<p>If you&#8217;ve been using &#8216;NUnit&#8217; you found yourself involved in doing repetitive actions like creating test projects and adding test classes and test methods.<br />
If you ever had a try with the &#8216;Rhino Mocks&#8217; mocking framework you had an extra bit of repetitive code to write, in all of your TestFixture classes.</p>
<p>I was tired of always creating a new test project for each project in my solution and manually add references.<br />
I was tired of always prepare test classes with Setup and Teardown methods as well as other standard elements.</p>
<p>Then I created a standard <strong>Project Template</strong> creating a test class library, an <strong>Item Template</strong> creating a Rhino Mocks enabled TestFixture class, and a couple of useful <strong>code snippets</strong>.</p>
<p>All this stuff is targeted to Visual C# projects.</p>
<h3><a title="requirementsrhino" name="requirementsrhino"></a><span style="font-size:small;color:#993300;">2. System Requirements</span></h3>
<p>You&#8217;ll need the following software:</p>
<p>Visual Studio 2005<br />
<a title="Nunit Home Page" href="http://www.nunit.org/index.php" target="_blank"> NUnit</a> (<a title="Download NUnit-2.4.7-net-2.0.msi" href="http://prdownloads.sourceforge.net/nunit/NUnit-2.4.7-net-2.0.msi?download" target="_blank">NUnit-2.4.7-net-2.0.msi</a>)<br />
<a title="Rhino Mocks Home Page" href="http://www.ayende.com/projects/rhino-mocks/documentation.aspx" target="_blank">Rhino Mocks</a> (<a title="Download Rhino Mocks 3.4" href="http://www.ayende.com/20/section.aspx/download/216" target="_blank">Rhino.Mocks-3.4.zip</a>)</p>
<p><strong>Important</strong>: Project references are based on Nunit default installation path and on Rhino.Mocks.dll being installed into the location %ProgramFiles%\RhinoMocks. To install Rhino in such a path just donwload the .zip file and unzip it there.</p>
<p><strong>Note:</strong> If your installation paths are different from the ones specified, you will need to modify project references once created a new test project with my template.</p>
<h3><a title="downloadrhino" name="downloadrhino"></a><span style="font-size:small;color:#993300;">3. Download and Install</span></h3>
<p>First of all download the file: <em>TDDTemplates.vsi</em> that you can find <a title="TDDTemplatesDownload" href="http://www.box.net/shared/20nsbuego0" target="_blank">here</a>.<br />
All you have to do is download, double click, and proceed with the installation.<br />
If you want more detailed description of what you are downloading, read further.</p>
<p>The file <em>TDDTemplates.vsi</em> is a Visual Studio installer file, containing:</p>
<ol>
<li>A Project Template named <span style="color:#003300;"><strong>Test Class Library</strong></span>;</li>
<li>An ItemTemplate named <strong>Test Class;</strong></li>
<li>Two <strong>Code snippets</strong> useful for test driven develpment (<strong>TDD Snippet</strong> component).</li>
</ol>
<p>Double-clicking on the installer file you will get a dialog window prompting you to choose wich of the listed items you want to install.<br />
Clicking on the <em>next</em> button you will get a message warning that the installer file is not signed.<br />
If you don&#8217;t want to install unsigned content you will need to create this installer by yourself and I will provide you with a brief tutorial in a future post.</p>
<p>If you will click the <em>yes</em> button, checked items will be installed:</p>
<ul>
<li> the <span style="text-decoration:underline;">Project Template</span> (Test Class Library.zip) will be installed into the location:</li>
</ul>
<p><span style="color:#808080;">%USERPROFILE%\MyDocuments\VisualStudio2005\Templates\ProjectTemplates\VisualC#</span> (where %USERPROFILE% is <span style="color:#808080;">C:\DocumentsandSettings\<em>username</em></span> in Windows Xp);</p>
<ul>
<li> the <span style="text-decoration:underline;">Item Template</span> (Test Class.zip) will be installed into the location:</li>
</ul>
<p><span style="color:#999999;">%USERPROFILE%\MyDocuments\VisualStudio2005\Templates\ItemTemplates\VisualC#</span>;</p>
<ul>
<li> a dialog will allow you to choose were to install <span style="text-decoration:underline;">Code snippets</span> (TDD.snippet):</li>
</ul>
<p>if you choose <em>My Code Snippets </em>the snippet file will be installed into the location:<br />
<span style="color:#999999;"> %USERPROFILE%\MyDocuments\VisualStudio2005\CodeSnippets\VisualC#\MyCodeSnippets</span>,</p>
<p>while if you choose <em>Visual C#</em> it will be installed under the Visual Studio installation directory, into the location:<br />
<span style="color:#999999;"> %ProgramFiles%\MicrosoftVisualStudio8\VC#\Snippets\1033\VisualC#</span>.</p>
<p><a href="#rhinotop"><span style="font-size:80%;color:red;">→ go to top</span></a></p>
<h3><a title="contentsrhino" name="contentsrhino"></a><span style="font-size:small;color:#993300;">4. Package Contents</span></h3>
<p><a href="#contents1rhino">4.1. Test Class Library Project Template</a><br />
<a href="#contents2rhino">4.2. Test Class ItemTemplate</a><br />
<a href="#contents3rhino">4.3. Code Snippets</a></p>
<p>In this paragraph you will find a detailed description of the contents installed by the Visual Studio installer we&#8217;re talking about: <em>TDDTemplates.vsi</em>.</p>
<h4><a title="contents1rhino" name="contents1rhino"></a><span style="font-size:x-small;color:#993300;">4.1. Test Class Library Project Template</span></h4>
<p>When creating a new project, the initial dialog will list a new project template under the <em>Visual C#</em> category: <strong>Test Class Library</strong>, as shown in the following image.</p>
<p><a title="Class Library Template in new Project dialog" href="http://ilmatte.files.wordpress.com/2008/01/projtemplatedialog.jpg"><img src="http://ilmatte.files.wordpress.com/2008/01/newprojectdialog.jpg" alt="New Project Dialog" /><br />
</a></p>
<p>If you rename the project: <em>ProjectName</em> and click <em>ok</em>, a new class library project will be created with the structure shown in the following screenshot of the Solution Explorer window:</p>
<p><img src="http://ilmatte.files.wordpress.com/2008/01/solutionexplorer.jpg" alt="Test Project Solution Explorer Screenshot" /></p>
<p>The file named <strong>Class1Tests.cs</strong>, created inside the project, contains the code defining the skeleton of a TestFixture class definition:</p>
<pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Mocks;

namespace ProjectName
{
    [TestFixture]
    public class Class1Tests
    {
        MockRepository mocks;

        ///
        /// Prepares mock repository
        ///
        [SetUp]
        public void Initialize()
        {
            mocks = new MockRepository();
        }

        ///
        /// template behavior and state testing method
        ///
        [Test]
        public void TestMethod1()
        {
            IDependency dependency = mocks.CreateMock();

            // Record expectations
            using (mocks.Record())
            {
                Expect
                       .Call(dependency.Method1(&quot;parameter&quot;))
                       .Return(&quot;result&quot;);
                dependency.Method2();
            }

            // Replay and validate interaction
            Subject subjectUnderTest;
            using (mocks.Playback())
            {
                subjectUnderTest = new Subject(dependency);
                subjectUnderTest.DoWork();
            }

            // Post-interaction assertion
            Assert.That(subjectUnderTest.WorkDone, Is.True);
        }
    }
}</pre>
<p>As you can see the class definition already contains a default implementation of a Test method.<br />
Such method includes the definition of RhinoMocks expectations for a hypothetical object under test.<br />
I chose to use Rhino Mocks new Record-playback Syntax which takes care of calling mocks.ReplayAll() and mocks.VerifyAll() under the hood.<br />
I feel this syntax is very neat and clean providing a clear separation between the moment in which we record expectations and the moment in which we use the object under test.</p>
<div><a href="#contentsrhino"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#rhinotop"><span style="font-size:80%;color:red;">→ top of post</span></a></div>
<h4><a title="contents2rhino" name="contents2rhino"></a><span style="font-size:x-small;color:#993300;">4.2. Test Class Item Template</span></h4>
<p>When adding a new item to the project, the <em>Add New Item</em> dialog will list a new project template: <strong>Test Class</strong>.<br />
It is possible that you have to scroll down a little to see the <strong>My Templates</strong> category, as shown in the following image:</p>
<p><img src="http://ilmatte.files.wordpress.com/2008/01/newitemdialog.jpg" alt="New Item Dialog Box" /></p>
<p>Selecting the <strong>Test Class</strong> template, a new class definition file will be created, containing the same class definition you obtained when creating the <strong>Test Class Library</strong> Project (see <a href="#contents1rhino">previous paragraph</a>).</p>
<p><a href="#contentsrhino"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#rhinotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h4><a title="contents3rhino" name="contents3rhino"></a><span style="font-size:x-small;color:#993300;">4.3. Code Snippets</span></h4>
<p>From now on, when writing code, you will have two more intellisense entries in your IDE: <em>TDDtestmethod</em> and <em>TDDusing</em>.</p>
<p><strong>TDDtestmethod</strong> will insert a test method definition as shown in the following sequence of images:</p>
<p><img src="http://ilmatte.files.wordpress.com/2008/01/tddtestmethod.jpg" alt="TDDtestmethod" /></p>
<p>Selecting the keyword as in the preceding image will produce the following code:</p>
<p><img src="http://ilmatte.files.wordpress.com/2008/01/tddtestmethodcontent.jpg" alt="TDDtestmethod Content" /></p>
<p>The snippet allows the user to choose the method&#8217;s Attribute (defaults to: Nunit.Framework.TestAttribute) and the methods name (defaults to: TestMethod).</p>
<p><strong>TDDusing</strong> will insert the two <em>using</em> blocks needed for the Rhino Mocks Record-playback Syntax, as shown in the following sequence of images:</p>
<p><img src="http://ilmatte.files.wordpress.com/2008/01/tddusing.jpg" alt="TDDusingRhinoSyntax" /></p>
<p>Selecting the keyword as in the preceding image will produce the following code:</p>
<p><img src="http://ilmatte.files.wordpress.com/2008/01/tddusingcontent.jpg" alt="TDDusingRhinoSyntax Content" /></p>
<p>The snippet allows the user to choose the instance of Rhino.Mocks.MockRepository<br />
to use for mocking objects.</p>
<p><a href="#contentsrhino"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#rhinotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a title="uninstallrhino" name="uninstallrhino"></a><span style="font-size:small;color:#993300;">5. Uninstall</span></h3>
<p>If you want to uninstall the installed content you can simply go to the paths specified in the <a href="#downloadrhino">Download and Install</a> paragraph and delete the correct files:</p>
<p>delete the file: <strong>Test Class Library.zip</strong> under:<br />
<span style="color:#808080;">%USERPROFILE%\MyDocuments\VisualStudio2005\Templates\ProjectTemplates\VisualC#</span></p>
<p>delete the file: <strong>Test Class.zip</strong> under:<br />
<span style="color:#999999;">%USERPROFILE%\MyDocuments\VisualStudio2005\Templates\ItemTemplates\VisualC#</span>;</p>
<p>depending on where you chose to install the snippets, find the file TDD.snippet file under:<br />
<span style="color:#999999;"> %USERPROFILE%\MyDocuments\VisualStudio2005\CodeSnippets\VisualC#\MyCodeSnippets</span>,<br />
or under:<br />
<span style="color:#999999;"> %ProgramFiles%\MicrosoftVisualStudio8\VC#\Snippets\1033\VisualC#</span><br />
and delete it.</p>
<p>That&#8217;s all.<br />
Feel free to post a comment if you want to report a bug or to propose enhancement of the templates and snippets.</p>
<p><a href="#contentsrhino"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#rhinotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a title="booksrhino" name="booksrhino"></a><span style="font-size:small;color:#993300;">6. Suggested Books</span></h3>
<p>Some useful reading about Test Driven Development and Nunit can be found in the following books:</p>
<table border="0">
<tbody>
<tr>
<td style="border:1px solid grey;text-align:center;" width="50%"><a href="http://www.amazon.com/gp/product/0321146530?ie=UTF8&amp;tag=myvionc-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321146530"><img src="http://ilmatte.files.wordpress.com/2008/02/21ja6f6ddvl_aa_sl160_.jpg" border="0" alt="" /></a><img style="border:medium none !important;margin:0 !important;" src="http://www.assoc-amazon.com/e/ir?t=myvionc-20&amp;l=as2&amp;o=1&amp;a=0321146530" border="0" alt="" width="1" height="1" /></td>
<td style="border:1px solid grey;text-align:center;" width="50%"><a href="http://www.amazon.com/gp/product/0977616673?ie=UTF8&amp;tag=myvionc-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0977616673"><img src="http://ilmatte.files.wordpress.com/2008/02/21ls-i2rxal_aa_sl160_.jpg" border="0" alt="" /></a><img style="border:medium none !important;margin:0 !important;" src="http://www.assoc-amazon.com/e/ir?t=myvionc-20&amp;l=as2&amp;o=1&amp;a=0977616673" border="0" alt="" width="1" height="1" /></td>
</tr>
<tr>
<td style="border:1px solid grey;padding:2px 5px;" width="50%"><a href="http://www.amazon.com/gp/product/0321146530?ie=UTF8&amp;tag=myvionc-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321146530">Test Driven Development: By Example (The Addison-Wesley Signature Series)</a><img style="border:medium none !important;margin:0 !important;" src="http://www.assoc-amazon.com/e/ir?t=myvionc-20&amp;l=as2&amp;o=1&amp;a=0321146530" border="0" alt="" width="1" height="1" /></td>
<td style="border:1px solid grey;padding:2px 5px;" width="50%"><a href="http://www.amazon.com/gp/product/0977616673?ie=UTF8&amp;tag=myvionc-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0977616673">Pragmatic Unit Testing in C# with NUnit, 2nd Edition</a><img style="border:medium none !important;margin:0 !important;" src="http://www.assoc-amazon.com/e/ir?t=myvionc-20&amp;l=as2&amp;o=1&amp;a=0977616673" border="0" alt="" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><a href="#rhinotop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filmatte.wordpress.com%2f2008%2f01%2f15%2fvisual-studio-nunit-rhinomocks-templates%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filmatte.wordpress.com%2f2008%2f01%2f15%2fvisual-studio-nunit-rhinomocks-templates%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ilmatte.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ilmatte.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilmatte.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilmatte.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilmatte.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilmatte.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilmatte.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilmatte.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilmatte.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilmatte.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilmatte.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilmatte.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=9&subd=ilmatte&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ilmatte.wordpress.com/2008/01/15/visual-studio-nunit-rhinomocks-templates/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3cb2e7cb9a15640aab9ac6639d9bc462?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/01/newprojectdialog.jpg" medium="image">
			<media:title type="html">New Project Dialog</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/01/solutionexplorer.jpg" medium="image">
			<media:title type="html">Test Project Solution Explorer Screenshot</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/01/newitemdialog.jpg" medium="image">
			<media:title type="html">New Item Dialog Box</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/01/tddtestmethod.jpg" medium="image">
			<media:title type="html">TDDtestmethod</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/01/tddtestmethodcontent.jpg" medium="image">
			<media:title type="html">TDDtestmethod Content</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/01/tddusing.jpg" medium="image">
			<media:title type="html">TDDusingRhinoSyntax</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/01/tddusingcontent.jpg" medium="image">
			<media:title type="html">TDDusingRhinoSyntax Content</media:title>
		</media:content>

		<media:content url="http://ilmatte.files.wordpress.com/2008/02/21ja6f6ddvl_aa_sl160_.jpg" medium="image" />

		<media:content url="http://www.assoc-amazon.com/e/ir?t=myvionc-20&#38;l=as2&#38;o=1&#38;a=0321146530" medium="image" />

		<media:content url="http://ilmatte.files.wordpress.com/2008/02/21ls-i2rxal_aa_sl160_.jpg" medium="image" />

		<media:content url="http://www.assoc-amazon.com/e/ir?t=myvionc-20&#38;l=as2&#38;o=1&#38;a=0977616673" medium="image" />

		<media:content url="http://www.assoc-amazon.com/e/ir?t=myvionc-20&#38;l=as2&#38;o=1&#38;a=0321146530" medium="image" />

		<media:content url="http://www.assoc-amazon.com/e/ir?t=myvionc-20&#38;l=as2&#38;o=1&#38;a=0977616673" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filmatte.wordpress.com%2f2008%2f01%2f15%2fvisual-studio-nunit-rhinomocks-templates%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>String representation of enumerations</title>
		<link>http://ilmatte.wordpress.com/2008/01/12/string-representation-of-enums/</link>
		<comments>http://ilmatte.wordpress.com/2008/01/12/string-representation-of-enums/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 15:43:47 +0000</pubDate>
		<dc:creator>ilmatte</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Enum]]></category>
		<category><![CDATA[enumconverter]]></category>
		<category><![CDATA[enumeration]]></category>
		<category><![CDATA[repurposing]]></category>
		<category><![CDATA[typeconverter]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[
1. Introduction
2. The problem
3. Other solutions
4. The goal
5. Example
6. Conclusion
7. Advantages of this solution
8. Full source code
1. Introduction
Use of enumerations greatly enhance readability of code and let client code be type safe and easier to write.
We don&#8217;t need to write sets of constant values and related validation code, we only need to properly define enumeration [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=1&subd=ilmatte&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a title="posttop" name="posttop"></a><br />
<a href="#introduction">1. Introduction</a><br />
<a href="#problem">2. The problem</a><br />
<a href="#other">3. Other solutions</a><br />
<a href="#goal">4. The goal</a><br />
<a href="#example">5. Example</a><br />
<a href="#conclusion">6. Conclusion</a><br />
<a href="#advantages">7. Advantages of this solution</a><br />
<a href="#code">8. Full source code</a></p>
<h3><a title="introduction" name="introduction"></a><span style="color:#993300;font-size:small;">1. Introduction</span></h3>
<p>Use of enumerations greatly enhance readability of code and let client code be type safe and easier to write.<br />
We don&#8217;t need to write sets of constant values and related validation code, we only need to properly define enumeration items.</p>
<h3><a title="problem" name="problem"></a><span style="color:#993300;font-size:small;">2. The problem</span></h3>
<p>Sometimes we want to use clear and simple names for enumeration values but we want to show more meaningful string representations in some GUI.<br />
This is were simply defining our custom enumeration is not enough.<br />
In fact default string representation of enum items relies on the EnumConverter class. But EnumConverter simply uses the enum item&#8217;s name as its string representation.<br />
<a title="other" name="other"></a></p>
<h3><a title="other" name="other"></a><span style="color:#993300;font-size:small;">3. Other solutions</span></h3>
<p>When I first needed to solve this issue, I browsed the web and found few good articles about repurposing enumerations, such as: <a title="Repurposing Enumerations" href="http://weblogs.asp.net/mnolton/pages/RepurposingEnumerations.aspx" target="_blank">Repurposing Enumerations</a> by Mathew Nolton and <a title="Localizing .NET Enums" href="http://www.codeproject.com/KB/cs/LocalizingEnums.aspx?df=100&amp;forumid=446955&amp;exp=0&amp;select=2211971" target="_blank">Localizing .NET Enums</a> by Grant Frisken, and few more.<br />
All of them rely on implementing a custom EnumConverter to be applied declaratively to the enumeration:</p>
<pre class="brush: csharp;">
[TypeConverter(typeof(CustomConverter))]
public enum MyEnum
{
   ...
}</pre>
<p>I found very instructive and interesting such approach but I still was not satisfied.<br />
What I dislike is the need to change client code from a simple:</p>
<pre class="brush: csharp;">
MyObject.Property = MyEnum.Item;
string humanReadable = MyObject.Property;</pre>
<p>to:</p>
<pre class="brush: csharp;">
MyObject.Property = MyEnum.Item;
string humanReadable = (string)TypeDescriptor.
GetConverter(typeof(MyEnum)).
ConvertTo(MyObject.Property, typeof(string));</pre>
<p><a href="#posttop"><span style="font-size:80%;color:red;">→ go to top</span></a></p>
<h3><a title="goal" name="goal"></a><span style="color:#993300;font-size:small;">4. The goal</span></h3>
<p>What I wanted was a pattern whose goal is to minimize the changes to client code while being as simple as possible to implement.<br />
All the articles that I read implied the need of a helper class (the custom EnumConverter), so I found it acceptable to implement a simple helper class too.<br />
I wanted a pattern providing a sort of separation of concerns: keeping Enumeration behavior unchanged while providing a means to control its string representation.<br />
The solution I&#8217;m going to illustrate is based on the use of <span style="text-decoration:underline;"><em>conversion operators</em></span> and I hope you will find it simple and straightforward.</p>
<p><a href="#posttop"><span style="font-size:80%;color:red;">→ go to top</span></a></p>
<h3><a title="example" name="example"></a><span style="color:#993300;font-size:small;">5. Example</span></h3>
<p>A typical situation could be a Clock application that we want to be able to display date and/or time in different formats.<br />
We will name the format choices using simple enumeration items (e.g.: <span style="font-size:12px;font-family:Consolas,Monaco,Courier New,Courier,monospace;">DateTimeFormat.Date, DateTimeFormat.Time</span>) but we&#8217;ll need to convert them in actual formats.<br />
The actual formats (e.g.: &#8216;dd/MM/yyyy&#8217;, &#8216;HH:mm:ss&#8217;) are needed to instruct the Clock object about how to render itself and its embedded DateTime in the form of a text string in a specific format.<br />
Take a look at the following code:</p>
<p><span style="font-size:90%;line-height:95%;"><span style="color:#3366ff;">remark:</span> note that comments on method calls in the client code state only the <span style="text-decoration:underline;">expected</span> behavior.<br />
</span><span style="font-size:90%;margin-left:40px;line-height:95%;">We will obtain it only at the end of the example.</span></p>
<pre class="brush: csharp;">
/***************
* Client code: *
****************/

Clock clock = new Clock();
// clock.DisplayedFormat accepts enumeration values
// (e.g.: 'DateTimeFormat.Date')
clock.DisplayedFormat = DateTimeFormat.Date;
// Enum value will be converted internally in the
// actual format and used by the Clock so that we can
// simply tell it to represent as string.
Console.WriteLine(clock);

// clock.DisplayedFormat returns the actual format
// string (e.g.: 'dd/MM/yyyy')
string format = clock.DisplayedFormat;
Console.WriteLine(format);

// ouptus:
// 10/01/2008
// dd/MM/yyyy</pre>
<p>Let&#8217;s implement the Types we need:</p>
<pre class="brush: csharp;">
/*************
* Enum code: *
**************/

public enum DateTimeFormat
{
    Date,
    Time
}</pre>
<p>Let&#8217;s Try and implement Clock&#8217;s basic functionality:</p>
<div><span style="font-size:90%;line-height:95%;"><span style="color:#3366ff;">remark:</span> the following code doesn&#8217;t work yet: using Enum values directly as formats</span><br />
<span style="font-size:90%;margin-left:40px;line-height:95%;">for DateTime.ToString( ) leads to incorrect results.</span></div>
<pre class="brush: csharp;">
/*************
* Clock code:*
**************/

public class Clock
{

  #region fields

  private DateTime m_CurrentDateTime = DateTime.Now;
  // defaults to Time format
  private DateTimeFormat m_Format = DateTimeFormat.Time; 

  #endregion
  #region properties

  /// &lt;summary&gt;
  /// format used to display current datetime
  /// &lt;/summary&gt;
  public DateTimeFormat DisplayedFormat
  {
      get
      {
          return m_Format;
      }
      set
      {
          m_Format = value;
      }
  }

  #endregion
  #region methods

   /// &lt;summary&gt;
   /// provides string representation of current DateTime
   /// depending on the format set.
   /// &lt;/summary&gt;
   /// &lt;returns&gt;returns current date or time&lt;/returns&gt;
   public override string ToString()
   {
       return m_CurrentDateTime.
              ToString(DisplayedFormat.ToString());
   }

   #endregion
}</pre>
<p>The three preceding slices of code don&#8217;t even compile because in the client code we need to provide explicit conversion from the Enum value to a string.<br />
So we need to replace the line:</p>
<pre>
</pre>
<pre>
</pre>
<pre>
<pre class="brush: csharp;">
string format = clock.DisplayedFormat;</pre>
</pre>
<p>with:</p>
<pre>
</pre>
<pre>
<pre class="brush: csharp;">
string format = clock.DisplayedFormat.ToString();</pre>
</pre>
<p>Now that the code compiles we still have some wierd results.<br />
In fact we provided a not meaningful format (the string representation of the enum value: &#8216;date&#8217;) to the m_CurrentDateTime.ToString( ) method.<br />
To let this code work we could implement a custom EnumConverter in order to represent the enum values as we like. But this choice would force us to modify client code as shown in paragraph: <a href="#other">&#8216;Other solutions&#8217;</a>.</p>
<div>We don&#8217;t want to do such a modification and we even want the correct string to be returned by simply writing:</div>
<pre>
</pre>
<pre>
</pre>
<pre>
<pre class="brush: csharp;">
string format = clock.DisplayedFormat;</pre>
</pre>
<p>To obtain the expected result we will implement a nested helper class named: <span style="font-size:12px;font-family:Consolas,Monaco,Courier New,Courier,monospace;">Format</span>.</p>
<pre class="brush: csharp;">
public class Format
{
   #region const

   const string
      Date = &quot;dd/MM/yyyy&quot;,
      Time = &quot;HH:mm:ss&quot;;

   #endregion
   #region fields

   DateTimeFormat m_CalendarFormat;

   #endregion
   #region .CTOR

   /// &lt;summary&gt;
   /// each Format instance represents a different value
   /// of DateTimeFormat enumeration
   /// &lt;/summary&gt;
   /// &lt;param name=&quot;calendarFormat&quot;&gt;DateTimeFormat value
   /// &lt;/param&gt;
   public Format(DateTimeFormat calendarFormat)
   {
       m_CalendarFormat = calendarFormat;
   }

   #endregion
   #region methods

   /// &lt;summary&gt;
   /// converts current Format instance into its string
   /// representation, i.e. the actual format string
   /// &lt;/summary&gt;
   /// &lt;returns&gt;actual format string represented by the
   /// current Format instance (e.g.: &quot;dd/MM/yyy&quot;)&lt;/returns&gt;
   public override string ToString()
   {
       return Convert();
   }

    /// &lt;summary&gt;
    /// converts enum values in actual datetime formats
    /// &lt;/summary&gt;
    /// &lt;returns&gt;returns valid datetime format&lt;/returns&gt;
    private string Convert()
    {
        string format = null;
        switch (m_CalendarFormat)
        {
            case DateTimeFormat.Date:
                format = Date;
                break;
            case DateTimeFormat.Time:
                format = Time;
                break;
            default:
                throw new Exception(
                              &quot;Format is not initialized!!&quot;);
         }
         return format;
     }

     #endregion
}</pre>
<p>Every instance of Format is initialized with a DateTimeFormat value and represents that<br />
value and the string representation we want for it.<br />
Now that we have the helper class we can replace <span style="font-size:12px;font-family:Consolas,Monaco,Courier New,Courier,monospace;">Clock.DisplayedFormat</span> returned type with: <span style="font-size:12px;font-family:Consolas,Monaco,Courier New,Courier,monospace;">Format</span>.</p>
<pre class="brush: csharp;">
private Format m_Format;
public Format DisplayedFormat
{
	get
	{
		return m_Format;
	}
	set
	{
		m_Format = value;
	}
}</pre>
<p>This would force us to change our client code like the following:</p>
<pre class="brush: csharp;">
Clock clock = new Clock();
// FOLLOWING ROW IS CHANGED
clock.DisplayedFormat= new Clock.Format(DateTimeFormat.Date);
Console.WriteLine(clock);

// clock.DisplayedFormat returns the actual
// format string (i.e.: 'dd/MM/yyyy')
string format = clock.DisplayedFormat.ToString();
Console.WriteLine(format);</pre>
<p>Now in client and Clock code the following row:</p>
<pre>
</pre>
<pre>
<pre class="brush: csharp;">
string format = clock.DisplayedFormat.ToString();</pre>
</pre>
<p>returns the correct string representation of the chosen format (i.e.: &#8216;dd/MM/yyyy&#8217;).<br />
At this point we&#8217;re still forced to make too many modifications to client code.<br />
This is where <em><span style="text-decoration:underline;">conversion operators</span></em> come in place!!</p>
<div>Conversion operators are particular static methods that we can overload to provide algorithms for conversion between types.<br />
We can implement an <span style="text-decoration:underline;">implicit</span> conversion operator allowing the runtime to perform automatic conversion or we can implement an <span style="text-decoration:underline;">explicit</span> conversion operator telling the runtime to throw an exception if client code doesn&#8217;t contain an explicit casting.</div>
<div style="padding-top:20px;">Let&#8217;s see implicit conversion operators at work adding the following two methods to the class: <span style="font-size:12px;font-family:Consolas,Monaco,Courier New,Courier,monospace;">Format</span>.</div>
<pre class="brush: csharp;">
/// &lt;summary&gt;
/// converts a DateTimeFormat value into a Format instance
/// &lt;/summary&gt;
public static implicit operator Format(DateTimeFormat arg)
{
	return new Format(arg);
}

/// &lt;summary&gt;
/// converts a Format instance into a string
/// &lt;/summary&gt;
public static implicit operator string(Format arg)
{
	return arg.Convert();
}</pre>
<p>The first one provides implicit conversion of DateTimeFormat values in Format instances.<br />
This allows us to set clock.DisplayedFormat by simply providing the enumeration value:</p>
<pre class="brush: csharp;">
clock.DisplayedFormat = DateTimeFormat.Date;</pre>
<p>The second one provides implicit conversion of a Format instance into its string representation, the actual format string (i.e.: &#8220;dd/MM/yyy&#8221;).<br />
This allows us to retrieve the desired actual format string by simply getting clock.DisplayedFormat:</p>
<pre>
</pre>
<pre>
</pre>
<pre>
<pre class="brush: csharp;">
string format = clock.DisplayedFormat;</pre>
</pre>
<p><a href="#example"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#posttop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h3><a title="conclusion" name="conclusion"></a><span style="color:#993300;font-size:small;">6. Conclusion</span></h3>
<p>Eventually, to achieve the desired result, we only need two things.<br />
We only need to implement the helper class and to replace the clock.Property returned type and it will work like a charm!</p>
<p><a href="#posttop"><span style="font-size:80%;color:red;">→ go to top</span></a></p>
<h3><a title="advantages" name="advantages"></a><span style="color:#993300;font-size:small;">7. Advantages of this solution</span></h3>
<p>Following are advantages of this solution:</p>
<ul>
<li>Simple to implement (it is more difficult to explain than to code)</li>
<li>No changes to client code needed</li>
<li>Separation of concerns (relying on Format class to convert enum values and not on the enumeration itself by means of a custom converter)</li>
<li><span style="text-decoration:underline;">Works with existing enumerations too</span></li>
</ul>
<p><a href="#posttop"><span style="font-size:80%;color:red;">→ go to top</span></a></p>
<h3><a title="code" name="code"></a><span style="color:#993300;font-size:small;">8. Full source code</span></h3>
<ul>
<li><a href="#clockcode">Clock code</a></li>
<li><a href="#clientcode">Client code</a></li>
</ul>
<h4><a title="clockcode" name="clockcode"></a><span style="color:#993300;font-size:x-small;">Clock Code:</span></h4>
<pre class="brush: csharp;">
/*************
* Clock code:*
**************/

using System;

namespace FormatProvider
{
  public enum DateTimeFormat
  {
    Date,
    Time
  }

  /// &lt;summary&gt;
  /// displays date or time
  /// &lt;/summary&gt;
  public class Clock
  {
    #region nested class

    /// &lt;summary&gt;
    /// encapsulate a DateTimeFormat and its
    /// string representation
    /// &lt;/summary&gt;
    public class Format
    {
      #region const
      const string
              Date = &quot;dd/MM/yyyy&quot;,
              Time = &quot;HH:mm:ss&quot;;
      #endregion
      #region fields

      DateTimeFormat m_CalendarFormat;

      #endregion
      #region .CTOR
      /// &lt;summary&gt;
      /// each Format instance represents a different value
      /// of DateTimeFormat enumeration
      /// &lt;/summary&gt;
      /// &lt;param name=&quot;calendarFormat&quot;&gt;DateTimeFormat value
      /// &lt;/param&gt;
      public Format(DateTimeFormat calendarFormat)
      {
          m_CalendarFormat = calendarFormat;
      } 

      #endregion
      #region methods

      /// &lt;summary&gt;
      /// provides implicit conversion of DateTimeFormat
      /// values in Format instances
      /// &lt;/summary&gt;
      /// &lt;param name=&quot;arg&quot;&gt;DateTimeFormat value&lt;/param&gt;
      /// &lt;returns&gt;Format instance corresponding to the
      /// DateTimeFormat value provided&lt;/returns&gt;
      public static implicit operator Format(
                                   DateTimeFormat arg)
      {
          return new Format(arg);
      }

      /// &lt;summary&gt;
      /// provides implicit conversion of a Format instance
      /// in its string representation, i.e. the actual
      /// format string&lt;/summary&gt;
      /// &lt;param name=&quot;arg&quot;&gt;a Format instance to convert in
      /// string representation&lt;/param&gt;
      /// &lt;returns&gt;returns the actual format string
      /// represented by the current Format instance
      /// (i.e.: &quot;dd/MM/yyy&quot;)&lt;/returns&gt;
      public static implicit operator string(Format arg)
      {
          return arg.Convert();
      }

      /// &lt;summary&gt;
      /// converts current Format instance
      /// in its string representation, i.e. the actual
      /// format string&lt;/summary&gt;
      /// &lt;returns&gt;actual format string represented by the
      /// current Format instance (i.e.: &quot;dd/MM/yyy&quot;)
      /// &lt;/returns&gt;
      public override string ToString()
      {
          return Convert();
      }

      /// &lt;summary&gt;
      /// converts enum values in actual datetime formats
      /// &lt;/summary&gt;
      /// &lt;returns&gt;returns valid datetime format&lt;/returns&gt;
      private string Convert()
      {
          string format = null;
          switch (m_CalendarFormat)
          {
              case DateTimeFormat.Date:
                  format = Date;
                  break;
              case DateTimeFormat.Time:
                  format = Time;
                  break;
              default:
                  throw new Exception(
                               &quot;Format not initialized!!&quot;);
          }
          return format;
      } 

      #endregion
    } 

    #endregion
    #region fields

    private DateTime m_CurrentDateTime = DateTime.Now;
    // defaults to time
    private Format m_Format = DateTimeFormat.Time;

    #endregion
    #region properties

    /// &lt;summary&gt;
    /// format used to display current datetime
    /// &lt;/summary&gt;
    public Format DisplayedFormat
    {
        get
        {
            return m_Format;
        }
        set
        {
            m_Format = value;
        }
    } 

    #endregion
    #region methods

    /// &lt;summary&gt;
    /// provide string representation of current datetime
    /// depending on the format set.
    /// &lt;/summary&gt;
    /// &lt;returns&gt;returns current date or time&lt;/returns&gt;
    public override string ToString()
    {
        return m_CurrentDateTime.ToString(DisplayedFormat);
    } 

    #endregion
  }
}</pre>
<p><a href="#code"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#posttop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<h4><a title="clientcode" name="clientcode"></a><span style="color:#993300;font-size:x-small;">Client Code:</span></h4>
<pre class="brush: csharp;">
/***************
* Client code: *
****************/

using System;
using FormatProvider;

namespace ClientCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Clock clock = new Clock();
            // clock.DisplayedFormat accepts enumeration
            // values (i.e.: 'DateTimeFormat.Date')
            clock.DisplayedFormat = DateTimeFormat.Date;
            Console.WriteLine(clock);

            // clock.DisplayedFormat returns the actual
            // format string (i.e.: 'dd/MM/yyyy')
            string format = clock.DisplayedFormat;
            Console.WriteLine(format);

            // output:
            // 08/01/2008
            // dd/MM/yyyy
        }
    }
}</pre>
<p><a href="#code"><span style="font-size:80%;color:red;">→ top of paragraph</span></a><br />
<a href="#posttop"><span style="font-size:80%;color:red;">→ top of post</span></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ilmatte.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ilmatte.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilmatte.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilmatte.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilmatte.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilmatte.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilmatte.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilmatte.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilmatte.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilmatte.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilmatte.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilmatte.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilmatte.wordpress.com&blog=2402635&post=1&subd=ilmatte&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ilmatte.wordpress.com/2008/01/12/string-representation-of-enums/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3cb2e7cb9a15640aab9ac6639d9bc462?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
	</channel>
</rss>