July 16, 2005 tools

My First MsBuild Task

Here. The one where I built my first custom msbuild task.
July 16, 2005 spout

My First MsBuild Task

I wrote my first custom msbuild task this morning. I used the the Extend the MSBuild with a New Task topic from the msbuild wiki and it worked well to get me started. I started with the simplest thing that used at least an input property:

// HelloTask.cs
using System;
using Microsoft.Build.Utilities; // reference assembly of same name
using Microsoft.Build.Framework; // ditto

namespace MyFirstTask {
  public class HelloTask : Task {
    string _who;

    [Required]
    public string Who {
      get { return _who; }
      set { _who = value; }
    }

    public override bool Execute() {
      Log.LogMessage(string.Format("hello, {0}!", _who));
      return true;
    }
  }
}

My task implements the msbuild ITask interface by deriving from the Task helper base class, which provides the Log object, among other things. The only thing I have to do is implement the Execute method, which needs to return true on success. To prove that my task is called, I use the Log object to log a message (I could also log an error or a warning). The public Who property is set from the use of the task in an msbuild file. By marking the property with the Required attribute, I ensure that msbuild itself makes sure that a Who is provided.

Once I’ve compiled my task, I can use it directly from a .proj (or .csproj or .vbproj) file:

<!-- fun.proj -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="HelloTarget">
    <HelloTask Who="Joe" />
  </Target>
  <UsingTask
    TaskName="MyFirstTask.HelloTask"
    AssemblyFile="C:\MyFirstTask\bin\Release\MyFirstTask.dll" />
</Project>

Notice the HelloTask element, which creates an instance of my HelloTask class and sets the Who property. The mapping between the HelloTask and the MyFirstTask.HelloTask class in the MyFirstTask.dll assembly is in the UsingTask element. Running msbuild against fun.proj yields the following output:

C:\taskfun>msbuild fun.proj
Microsoft (R) Build Engine Version 2.0.50215.44
[Microsoft .NET Framework, Version 2.0.50215.44]
Copyright (C) Microsoft Corporation 2005. All rights reserved.

Build started 7/16/2005 7:04:09 PM.
__________________________________________________
Project "C:\taskfun\fun.proj" (default targets):

Target HelloTarget:
hello, Joe!

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:00.04

Notice the hello, Joe!” output by the task as its Execute method is called. Notice also that while the task is in its folder, the .proj file can be anywhere, so long as it has a UsingTask that maps appropriately. By convention, the UsingTask elements are kept in .targets files and put into shared folders to be used between multiple project files, e.g. Microsoft.common.targets, etc. Refactoring the UsingTask out of the .proj file and into a .targets file looks like this:

<!-- My.Fun.targets -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask
    TaskName="MyFirstTask.HelloTask"
    AssemblyFile="C:\MyFirstTask\bin\Release\MyFirstTask.dll" />
</Project>
<!-- fun.proj -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="HelloTarget">
    <HelloTask Who="Joe" />
  </Target>
  <Import Project="c:\My.Fun.targets" />
</Project>

Of course, a real task does far more than this one, but it was hella easy to get started.

July 12, 2005 .net

Amazing XAML Tool: Adobe Illustrator -> XAML

Mike Swanson has posted an amazing Adobe Illustrator to XAML conversion tool. You have to check out the eye candy page to really see what Mike’s been able to accomplish; it’s not perfect, but it’s damn good.
July 12, 2005 tools

Eric Sink: The Game is Afoot

I don’t know if Eric understands the ISV industry or not, but certainly seems to. Luckily, I’m on a real product team now, so I get to try to channel Eric into my work.

Eric’s latest writing is The Game is Afoot, in which he describes various games and then draws lessons from them for ISVs. It’s fabulous. He concludes by apologizing for the length and then teasing us with the analogies he left off. It wasn’t too long, Eric! I wanted more! (I also want your blog to have comments, but that’s another thing entirely…)

I think now I understand the public outcry when I suggested that I might cut down on the material in the Windows Forms 2.0 book

July 12, 2005 tools

Looking forward to the Portland Code Camp, 7/23-24

The session list for the Portland Code Camp, July 23-24, has just been posted. I’m especially looking forward to the following:

  • .NET Windows Forms Tips & Tricks
  • Forensic Development
  • Implementing Creature AI
  • Introduction to Inform
  • Introduction to Python
  • Introduction to Ruby
  • Ruby on Rails
  • MonoRail - ASP.NET on Rails
  • Web Unit Testing with Ruby and Watir

That’s only if my wife doesn’t have my working on the house (we’re prepping it for sale). Of course, I don’t know if she’ll understand that I’ve volunteered to give my own session: Some Cool Avalon Stuff

July 10, 2005 spout

Enjoying This Moment

Here.

The one where I enjoy the passing of the book writing storm, if only for a moment.

July 10, 2005 spout

Is it creepy that I think this is valid?

I’ve used this technique to keep people from dumping their work on me. Now I’m creeped out about it…
July 10, 2005 spout

Enjoying This Moment

I’m sitting at my computer on Sunday morning with nothing” to do (I mean, I could always work, but my team is good about taking weekends off). This morning comes after 3.5 months straight of evenings and weekends working on the Avalon book (I’m talking 20+ hours/week on the book on top of the 50-60 hours/week I spent getting up to speed on my new job). The final push was this week, which I took as vacation from work (“you took vacation to work!” my wife likes to say…).

Last night, I produced the 2nd draft of my last 1st draft chapter (which I was happy to trim by 17 pages w/o losing anything useful) and composed comments on a 2nd draft of Ian’s chapter that was in my queue.

This morning, I took care of a reviewer comment that’s been nagging me, sent Ian my feedback and composed a detailed schedule of the rest of my day which consists of:

  • wait for feedback on non-finalized chapters
  • apply feedback and finalize my last two chapters (30-60 minutes)
  • produce 2nd draft of book preface (1-2 hours)
  • review anything Ian sends my way (1-2 hours)
  • (maybe) review 1st draft of chapter from the WinForms 2.0 book (1-2 hours)

Compared to how I have been spending my time lately, that’s an extremely light day.

This book has been particularly difficult to write. Most of my writing has been on insights that I or the other members of the community have discovered in the use of the technology. These kinds of insights come after the technology is shipped and we’ve all had a chance to get to know it. Avalon, on the other hand, has a ways to go before it ships and the developer community is very small. Plus, some parts of Avalon don’t work very well or have changed significantly since I first learned about them. The consequence of this is that most of my writings on Avalon have had to have at least one massive overhaul as I a) learn the best way to think about them and b) update them to actually reflect the latest bits.

The rub is that by the time the book sees the light of day (it should be on the PDC show floor), the Avalon team will likely have shipped another version of the bits, obsolescing what Ian and I have worked like dogs to ship. Of course, we’ll post the errata and we’ll update the book for the Avalon RTM, but still, it hurts that most of you won’t be able to read the book when it’s a perfect match for the bits.

I get to read it, though, and I’ll tell you — right now, the book rocks. : )  And the reason it rocks? Ian and I have worked hard to make sure it does, of course, but it’s mostly been the internal and external reviewers that have done such a great job pointing out where we got it wrong. It’s tough to hear, especially when it means a complete chapter re-write (I just finished one of those last night), but I’m so happy with the results that I’m willing to love them anyway.

Now I’ve raised the bar impossible high, but screw that — I’m enjoying the moment…


← Newer Entries Older Entries →