Showing posts with label cruisecontrol. Show all posts
Showing posts with label cruisecontrol. Show all posts

Monday, March 21, 2011

Watching Ideas Take Flight

In my last entry, I mentioned an idea I’d had before on how to make it easier to package .NET applications when run as part of an automated build. It solved a problem for me, and I thought it worth sharing, firstly as an aide mémoire for myself, and secondly because it seems the sort of thing that other people would find useful.

Rob Reynolds came across my post, and he obviously found it useful. In fact, he liked it so much that he has put together a NuGet package to make the set-up of _PublishedApplications even easier, together with a demo of how easy it is to use.

Demo of _PublishedApplications at work

I’m thrilled to see this getting out there – a big thanks to Rob for really getting this off the ground, as well as giving it more exposure.

Thursday, March 10, 2011

Publishing .NET Applications

This is a problem I came across in my previous job at Fairfax Digital, when setting up automated builds; now that I am working at TouchStar, I’m facing the same problem, but couldn’t remember what I did the first time round.

The problem is this: when building ASP.NET web applications using TFS or some other continuous integration solution (I’m using UppercuT at TouchStar), the MSBuild engine very conveniently creates a _PublishedWebsites folder in your output folder, and then creates a subfolder in that folder for each website that you are creating. So far, so good. However, when building executable applications, such as console apps, WPF applications or Windows services (and I’m building all three at TouchStar) then it just throws everything into one directory, and leaves it to you to pick out the bits you need. “If only you could export your build results to a _PublishedApplications folder!”, I hear you cry.

Well, that’s essentially my solution. I took a copy of the Microsoft.WebApplication.targets file that is referenced in the ASP.NET project file, renamed it to Microsoft.Application.targets and saved it to C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Applications. I then tweaked it, renaming variables and such to match the type of content, and removing any references to /bin folders. I then reference the new file in the Visual Studio project file by adding the following line:

  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Applications\Microsoft.Application.targets" />

And voila! I now have one folder per application in the _PublishedApplications folder when run as part of an automated build. If I build from within Visual Studio, outputs are still sent to their usual location (e.g. /bin/Debug/). I’ve included a link to the file below.

[Download Microsoft.Application.targets]

Thursday, August 12, 2010

Mixing TFS 2008 and VS 2010

At work, we’re in the early phases of migrating our TFS 2008 setup to TFS 2010. However, since some teams have already started work on the new hotness that is VS 2010 and .NET 4, there was a need for us to get their automated builds up and running immediately. We “requisitioned” a desktop that was already running builds for another semi-defunct project using CruiseControl.NET, and installed Team Build on it.

It took a few tweaks to get the code compiling, but something was wrong with the testing phase – the tests would run, but the test runner would then report a failure, resulting in a yellow warning lights rather than nice green success lights. The error message was:

MSBUILD : warning MSB6003: The specified task executable "MSTest.exe" could not be run. The system cannot find the file specified [D:\Source\CommonPlatform\Common Platform Development CI Build\BuildType\TFSBuild.proj]

So the tests all passed, but then Team Build couldn’t find the testrunner that it had just used! We tracked down another user with the same complaint on StackOverflow, but they were shouting in the dark, with no response to their question.

After much head-scratching alternated with banging our heads against the wall and wondering why Microsoft products are sometimes to great and sometimes so plain awful (often in the space of just five minutes), we eventually found the solution to our problem tucked away in forum on MSDN. The TeamBuild targets file which imports the TestToolsTask has an invalid path reference:

<UsingTask TaskName="TestToolsTask" AssemblyFile="$(MSTestRefPath)\Microsoft.VisualStudio.QualityTools.MSBuildTasks.dll" 
Condition="'$(ProjectFileVersion)' == '2'" />

since MSTestRefPath doesn’t appear to be defined in VS 2010. By changing it to the correct path, the test runner can be found again, and the error disappeared.

Quite why Microsoft implemented it so that the tests would run but then fail afterwards I don’t know, but at least our builds are all happy, and the developers are happy. Hopefully we can now get back to migrating TFS 2008 to 2010, and we can see the back of this problem.

Wednesday, May 20, 2009

SvnRevisionLabeller makes its v2 release

Recently Thoughtworks started to make available release candidates for version 1.4.4 of CruiseControl.NET. Tucked away inside there though are some changes to some of the core components, that break compatibility with SvnRevisionLabeller.

This gave me the proper motivation to find some time to finish off the packaging of a fairly major change to the way the labeller constructs build labels. The real work was actually done by another developer, fezguy - I just had to integrate his patch, tweak it to the way I like things (hey, it is my project after all!), and finally start work on some automated tests. I like automated tests.

Since the two changes combined do break backwards compatibility, it's good to take a step back and see where we are now.

Before, SvnRevisionLabeller was quite opinionated about how it thought build labels should be structured. With version 1.1, it was {major}.{minor}.{svnRevision}.{build} - {build} would start at 0, then if you forced another build without another commit having taken place, it would be incremented by one. A commit would then reset {build} back to 0, so you had a good idea how often the build was being forced. I later added the ability to specify prefix and suffix text for the label.

Version 1.3 saw me rethink things a bit, with the label now defaulting to {major}.{minor}.{build}.{svnRevision}; now, successive forced builds made no difference to the label. What it did give me was that when I deployed a hotfix to production (usually designated by the incremented {build} number), I could tell immediately which Subversion revision it was built with.

So it obviously works the way I wanted it to - but what about other people? Version 2.0 makes the label scheme very flexible - some tokens are defined, and you just position the tokens wherever you want them in a string pattern. So for instance, if I set my configuration thusly:

<labeller type="svnRevisionLabeller">
<major>1</major>
<minor>4</minor>
<build>2</build>
<pattern>Release v{major}.{minor}.{build} from {revision}</pattern>
</labeller>

then when revision 42 is committed, the build label will become Release v1.4.2 from 42. At work, I use the {build} number to represent the sprint number since we began working on the {minor} release.

Finally, I noticed that my project was not the only one to be caught out by CC.NET's upgrade - Codeplex's CC.NET Community Plugins are also broken by the change; unfortunately, they have a little more work to do, as it's not just a question of updating their external libraries and recompiling. I'm rather underwhelmed by the amount of activity on the site: I raised an issue earlier this month, and then submitted a patch to fix the issue, and it still hasn't been acknowledged yet, let alone added to the repository. For the time being, I won't be upgrading to v1.4.4 at work, since we need that library for our deployments.

Friday, February 13, 2009

Catching Up

It's been a while since my last release of SvnRevisionLabeller, and I've not paid the project pages too much attention, seeing as everything was very quiet. Unfortunately, I hadn't set up the project to notify me whenever issues were raised, so I'd missed the raising of several bug or change requests.

Well, after stumbling upon one such change request during an unrelated Google session, I thought I'd better catch up on my project maintenance; it doesn't look very professional when your projects have bug reports unloved, unacknowledged, and unresolved.

The biggest change is that build number will be configurable; it was one of the first feature requests, and for a current project at work, it's something I wanted to do anyway.

BTW if you have downloaded and installed the plugin, I'd be interested to know. Google reports 822 downloads; the person who filed that request has linked to their site, so that's one, and of course I use it at Fairfax Digital, so that's two. Anyone care to offer up any of the other 820 downloads?!

Wednesday, February 11, 2009

Using Sandcastle with CruiseControl.NET

For a new project at work, I'm adding automatically-generated API documentation as part of my nightly build. Back in the days of .NET 1.1, we had the NDoc project, and explicit support for it in NAnt. Unfortunately, the project never made the transition to .NET 2.0, instead coming to a rather bitter and public end due to predominantly a lack of community support (despite the large numbers of downloads). I guess it's one the main failing of open-source projects - many are happy to take, but not so happy to give (whether money or time/effort).

Sandcastle is Microsoft's official documentation generator, but even three years on, it lacks some of the user-friendliness that any NDoc user had come to expect. The Sandcastle Help File Builder tool goes a long way to rectifying this, but most of the focus is on the GUI tool. Until the current v1.8 release, command line builds were taken care of by the SandcastleBuilderConsole.exe tool; however, the latest release drops this, and instead uses MSBuild, which ships with the .NET Framework. This is a rather nice touch, in my opinion - a clever use of existing tooling, rather than writing another new tool.

However, the documentation about using it in a continuous integration environment is still a little lacking, so I'm documenting here the problems I came up against.

Installation

So far, it seems like neither Sandcastle nor SHFB have been designed with easy deployment in mind. I like to include my build tools within my source repository; this saves a lot of tedious installation and configuration whenever setting up a new developer PC. Both tools come as MSI packages, with Sandcastle deploying as a 220Mb install, so maybe that one you can do without in your repository! SHFB on the other hand is relatively lightweight, at around 3Mb for the files required by the build tasks. You will need to set an environment variable for it to run properly, though:

<setenv name="SHFBROOT" 
   value="${Sandcastle.dir}" 
   unless="${environment::variable-exists('SHFBROOT')}" 
   verbose="true" />

The SHFB files that you seem to require are:

  • ColorizerLibrary.dll;
  • ICSharpCode.TextEditor.dll;
  • SandcastleBuilder.Components.Config;
  • SandcastleBuilder.*.dll;
  • SandcastleHelpFileBuilder.targets;

You'll also need the Help 2.0 Compiler tool hxcomp.exe, which ships as part of Visual Studio 2008 SDK; and of course, the SDK requires that Visual Studio 2008 is installed before it itself will install. Fortunately, you can pull out the contents of C:\Program Files\Common Files\Microsoft Shared\Help 2.0 Compiler\ and add that to your repository as well, bypassing that little pain-in-the-neck.

Configuration

To use SHFB within CC.NET with NAnt, you'll need the <msbuild> task that comes with NAntContrib. The syntax is as follows:

<msbuild project="${source.basedir}\Documentation.shfbproj">
   <arg value="/property:${HxComp.dir}" />
   <arg value="/property:SandcastlePath=C:\Program%20Files\Sandcastle\" />
</msbuild>

All the properties listed in the SHFB GUI tool can be set as above - just watch out for the need to escape spaces when hard-coding paths, which had me stumbled for an hour or two, until I found a post asking the same question.

Still To-Do

The one thing I really want to get done is programatically set the assemblies which will be documented; at the moment, you either use the GUI tool and relative paths, or edit the SHFB project file by hand. You could probably also use NAnt's <xmlpoke /> task to edit it, but I would prefer to be able to set it via parameters to the <msbuild /> task, so watch this space while I work it out.

Wednesday, March 28, 2007

CruiseControl.NET and Subversion Revision Labeller plug-in

Last year, I finally managed to get into automated builds at work. We write a lot of platform code for the other business units in our organisation, so any bugs/defects have quite a high visibility; what could be a better way of improving the transparency of our processes than having an easily accessible automated build system, which would not only compile and test our code, but create release/deployment packages, all before we had even arrived at the office? It didn't take too long to get CruiseControl.NET up and running, using a fairly typical open-source blend of Subversion, NAnt, NAntContrib, NUnit etc etc, whicb should all be familiar to anyone who has read Open Source .NET Development, which should really be required reading for all .NET programmers. Using NAntContrib's <version> task, it's easy enough to automatically set the version number in an assembly. What it didn't allow us to do was pass that information back up to CruiseControl for display in the web dashboard or the system tray application for more immediate feedback. So I decided to knock up a plug-in to do just that. I'd already played about with plug-ins for open-source applications, so it wasn't quite so much of a big step. So in October 2006, I posted to the ccnet-user group, announcing the creation of the plug-in, inspired by a blog entry by Jonathan Malek. I got a response from Richard Hensley, who was putting together a library of plug-ins, suggesting I might want to add my code to his library, but unfortunately I haven't had any response to my emails. So I thought I'd take matters into my own hands, and post directly to the CC.NET community site; you can imagine my surprise when I saw that someone else has, fairly recently, also uploaded a Subversion revision labeller! Fortunately, there are enough differences between the two to make it worth uploading; so I now have two contributions to the open-source community, both small and specific to my job, but hopefully useful enough for others to use. Now I just have to get the NAntContrib guys to actually include mine in the builds...

Tuesday, September 12, 2006

CruiseControl.NET - Using the Multi SourceControl block with filters

As some have been led to observe, the documentation that goes with CruiseControl.NET is, charitably speaking, a little sparse. This is particularly true of the Multi SourceControl Block, which, unsurprisingly, allows the use of multiple source control blocks in a project. In the project that I am currently working on, I have some five separate CVS projects to check, and to add to the fun, I wanted to add some path filters to the mix. So, after a little trial and error, and a quick peek at the source code, here's a code sample for using path filters with multiple source control providers:
<sourcecontrol type="multi">     <sourceControls>         <filtered>             <sourceControlProvider type="cvs">                 <executable>C:\Program Files\cvsnt\cvs.exe</executable>                 <workingDirectory>D:\Cvs\Services</workingDirectory>             </sourceControlProvider>             <exclusionFilters>                 <pathFilter>                     <pattern>**/build.number</pattern>                 </pathFilter>                 <pathFilter>                     <pattern>**/CommonAssemblyInfo.cs</pattern>                 </pathFilter>             </exclusionFilters>         </filtered>         <filtered>             <sourceControlProvider type="cvs">                 <executable>C:\Program Files\cvsnt\cvs.exe</executable>                 <workingDirectory>D:\Cvs\Console</workingDirectory>             </sourceControlProvider>             <exclusionFilters>                 <pathFilter>                     <pattern>**/build.number</pattern>                 </pathFilter>                 <pathFilter>                     <pattern>**/CommonAssemblyInfo.cs</pattern>                 </pathFilter>             </exclusionFilters>         </filtered>     </sourceControls> </sourcecontrol>