gists, csharp, build comments edit

We use NAnt to automate our build process, and right now I’m working on refactoring the build that my group uses for continuous integration. One of the things I noticed is that when our product builds, the main build file “includes” a few other build files and executes targets from them. One of the build files that gets included only ever has one target called, and it does a bunch of internal work to get a lot of things done. It looks a lot like this:

Build script

Notice how there’s only one entry point in the external build file and the tasks inside call other tasks, some of which are common, almost like NAnt “functions” that pass parameters by setting properties. Not only that, but part of the build output for the product is to include this build script so other products can include it and use it in the same way. I don’t know about you, but this says “custom NAnt task” to me.

In converting this to a custom NAnt task, I found that part of what the script was doing was calling other custom NAnt tasks. Not wanting to replicate all of the functionality of these other custom NAnt tasks, I figured I’d write my custom task to call the other tasks programmatically.

Interestingly enough, this isn’t as straightforward as you might think, and NAnt documentation on this is, well, light. You can’t just create the task object and call it, you actually have to give the created task some context about the environment it’s working in. You do this by calling the CopyTo method on the task object. By and large, the way it looks is this:

using System;

using NAnt.Core;
using NAnt.Core.Attributes;
using NAnt.Core.Tasks;

namespace MyCustomNAntTasks {
  public class MyCustomTask : Task {
    protected override void ExecuteTask() {
      this.Log(Level.Info, "Starting custom task...");

      // Create and execute a <tstamp /> task
      this.Log(Level.Verbose, "Executing a tstamp task...");
      TStampTask tstamp = new TStampTask();

      // Create and execute a <sysinfo /> task
      this.Log(Level.Verbose, "Executing a sysinfo task...");
      SysInfoTask sysinfo = new SysInfoTask();

      this.Log(Level.Verbose, "Executing custom work...");
      // TODO: Insert your custom task's work here

      this.Log(Level.Info, "Custom task complete.");

That seems to work well for most tasks. Some tasks require more initialization than just CopyTo, like the setting of properties or what-have-you, so you’ll need to set that stuff up for things to work since you don’t get the validation benefits that you get when NAnt parses the build script and tells you when you’re missing required values.

One task I haven’t gotten to work like this is the <csc /> task - for some reason, I haven’t figured out how to properly add references to the task to get it to work. Instead of calling <csc />, I ended up writing a quick method using the Microsoft.CSharp.CSharpCodeProvider to compile things directly.

Minor update: I actually ended up having to use an <exec /> task to build the code rather than the Microsoft.CSharp.CSharpCodeProvider because I didn’t see a way with the code provider to specify a target framework, whereas you can call the framework-specific csc.exe based on NAnt project settings and the correct framework will be used.

Saturday was an errand day (running around to various stores, picking things up as needed, general taking-care-of-business) followed by a bit of evening gaming with Stu, but Sunday… Sunday almost all day was dedicated to Tomb Raider: Legend. I think I must have played for six hours. They really did an awesome job with it and I’m having a great time.

In other news… I should shortly have a new version of CR_Documentor out that will not only let you preview the XML doc but will also preview the member syntax box inline with the doc, just like the NDoc output. I’ve got some folks doing some testing for me to make sure it doesn’t break anything, but that should be done soon. I’ll keep you posted.

I ordered a copy of Tomb Raider: Legend a while ago and it came in the mail last night. It also came with a lithograph (reads: picture printed on cardstock) of the image from the cover of the box, which is pretty cool.

While Jenn and I were out last night I picked up the “el cheapo” frame at Jo-Ann for $2 so I could put it up in my cube and have something to hang it by (I’m not a big fan of poking holes in my pictures, so the frame basically serves as a picture hanging device).

I got it all the way to work and started getting out of the car with it this morning when I realized my hands were pretty full - coffee, computer bag, name badge, picture… Should I put something down or make a couple of trips? Nah…

…at which point my coffee decided to spill out the travel mug and all over the picture.

I’m not sure if you’ve ever had coffee inside a picture frame (like between the picture and the glass), but that’s a bitch to clean up. Sticky, greasy… ugh. Nightmare.

Everything came out fine in the end (no big deal if it hadn’t, but it’s nice when there’s no loss). Maybe next time I’ll put stuff down or make two trips.

Or maybe I’ll just keep on doin’ what I’m doin’ and screw it up again. Which is more likely?

I hadn’t seen the first season of 24, so this past Saturday my dad brought it over, Stu showed up, and we had another 24 marathon.

Once again, well worth the time spent. I can see totally why the show took off. Great cast, great writing… it doesn’t get much better.

It also showed me how they reward long-time viewers: if you watch carefully, you can see peripheral characters from previous seasons show up in later seasons with larger parts, tying things in together nicely.

My dad ended up loaning Stu the second season so he can catch up, which is cool. That’s where I started. Stu also apparently had the weird 24 surreal after-effect I had after my first marathon where he just had to call Jack and tell him about the bomb on the plane at 3:00a. Funny, but understandable. Heh.

Dad says the fifth season is the best yet, so I’m excited for this fall when it comes out on DVD.

windows, aspnet comments edit

Scott Guthrie has a great article about some of the IIS 7 features coming in Windows Vista and Longhorn. Included:

  • HttpHandlers and HttpModules can participate in any server request, not just for .NET apps.
  • ASP.NET configuration system integrated into IIS (web.config for all apps!).
  • Admin GUI that combines administration of IIS and ASP.NET settings.
  • Better error auditing/debugging through a new system called “Failed Request Event Buffering.”
  • Vastly improved APIs (check out the example of the simplest program ever that can enumerate the worker processes and current requests). Check this out for more on the API updates. Bye bye, WMI!

I’m stoked. Seriously. All of this stuff is going to make the ASP.NET world so much easier to work in. I’ve already started shooting emails off to folks around work about ways we can leverage these things.