AJ's blog

December 2, 2006

Got GAT?

Filed under: .NET, .NET Framework, C#, Design Time, Software Developers, Software Development — ajdotnet @ 2:38 pm

I have been working with the Guidance Automation Toolkit (GAT) for some time now and thought I could give you a little motivation to look into it yourself.

What is GAT anyway?

GAT is a framework to build Visual Studio addins of a certain kind. Emphasis here is on the ‘G’ in GAT, G like “Guidance“. GAT makes it very easy to provide the user of the GAT package you developed (i.e. another developer) with templates, snippets, and most importantly with wizards and the ability to fullfill complex tasks. Typical usage scenarioas may include:

  • Create a new class (boilerplate code), say an exception or form, based on user input (wizard), register it with some kind of configuration (complex task), enterprise library exception handling or UIP application block, and update the project structure accordingly, i.e. create the project entry, deal with SCC, etc. (again comlex task)
  • Create code based on some configuration or other information. E.g. generate standard web pages supporting display and CRUD operations on data, based on an existing dataset or XML schema.
  • Create your own wrapper class for some service description (like WSDL or other) that adresses special needs such as error handling or logging.

In other words, use GAT …

  • whenever you have to create a new code file that is boilerplate but requires a few parameters (a Wizard) and is a little too complex for code snippets.
  • whenever you have to create a family of related code files (as group, all or none), say a form and accompanying resource and configuration file.
  • whenever creating a new file requires addition work, like registering it in a central configuartion file
  • whenever work shall be triggered via context menu entries on project items
  • whenever these things span multiple projects or depend on project types
  • whenever these things need to be done “transactional”, i.e. support an undo mechanism

How does it work?

GAT is a bit like Lego. It’s a set of small building blocks of different type and for different purpose. There are references, type converters (rings a bell, doesn’t it?😉 ), value providers, actions, all playing nicely together. Just like with Lego you have to know how the pices work together, not only where to fit them in but how to shape them into a working system. On the other hand, many of the components you will undoubtedly have to write tend to be very reusable — if you do it carefully — and quite often are unrelated to the specific task at hand. A recipe to update a config file for web applications? A type converter that provides a list of the web projects within the current solution — or better yet, it can be configured to show this or that kind of projects — has nothing to do with the special config file.

The place for assembling the pieces into a larger system is a central XML file in each GAT package. Here you describe logical units of work, called recipes. A recipe usually contains four major parts:

  • infrastructure information, like in which menu the recipe will be available, which text and icon it will show.
  • arguments or rather data declaration. This is where “variables” are declared and associated with type converters and value providers
  • a wizard to get information from the user
  • a sequence of actions to do the actual work

This set up reminds me a bit of COBOL file structure😉

The XML file may contain multiple recipes and it also has some global infrastructure information, like name or help file URL. There is also a special recipe called during the registration of the GAT package, used to register the other recipes. This registration employs a reference object that further decides whether the respective recipe will be available or not (e.g. one may check the current project type and only allow the menu entry in web projects).

Recipes may be the the major concept in GAT but it certainly does not stop here. GAT also includes template engines (solution, project, and file templates), packages may install code snippets, and it comes with a management component for the end user (the “Guidance Package Manager”).

What can’t be done?

Whatever you do plainly with GAT is available via GAT only and surfaced to the user mainly via menu entries on project items (with the exception of solution and project templates). The consequences:

  • No way to react on anything but menu entries, especially not on other Visual Studio events, say starting a recipe automatically when saving a file. To accomplish that you’ll have to build a regular addin the hardcore way.
  • No way to use the actions somewhere else, in paritular no way to leverage them within the build process. MSBuild support or some command line tool would be more suited to that need.
  • GAT is also not exactly suited to work “within” a file, i.e. provide recipes that modifies a part of an existing code file, available depending on the current cursor location. Something like “Implement Interface” or “Encapsulate Field” in the context menu depending on whether you are at the location of an interface or a field. Again this would be better done within a regular addin. (Fortunatelly someone within Microsoft allready thought of the examples I just mentioned…)

It is not as if GAT is out of question in these cases. It just won’t solve all requirements and you need to carefully plan a layered implementation approach. Put core functionality in a Core.DLL and call it from a GAT action as well as from your favourite command line tool.

Famous last words…

Well, it has to be said: GAT is only a Technology Preview right now. It’s quite stable and fairly complete, but some things may need some improvement (user fedback in error cases, SCC awareness, shortcommings of existing components). Another issue is the documentation which is better than one would expect but still needs a good deal of improvement. And of course noone knows whether the next release will break existing code and no final release date has been announced yet.

Anyway, if the above description of GAT sounds like something you have been looking for I recommend to give it a try. For those interested: there is a forum in which you will even get feedback from the authors and a dedicated GAT web site which also has sample code.

That’s all for now folks,
AJ.NET

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: