Wednesday, January 30, 2008

Building C# projects with Windows Workflow

wfbuild After reading a post about using Windows Workflow to build an SMTP server, I started thinking of something I could use WF for outside the world of business processes. For a long while I've also been planning on automating my build processes for various projects I've got on the go. I then realised I could combine the two and develop an automated build system with WF. At this point, if you have any experience of automated builds, you're probably thinking "Why the hell don't you use NAnt or MSBuild like any normal person?", which is a fair point.

But using WF has a few advantages. First, as far as I'm aware NAnt and MSBuild don't provide a graphical designer for their build projects (I'm quite happy to be proved wrong on this point) whereas I was able to knock together a designer based on the Microsoft example pretty quickly. Second, I just wanted to use WF for something not related to business processes. It is a very flexible technology and I'm not sure people have realised its potential. I blame the name, which makes everyone assume WF has something to do with workflow, which for many people has a very particular meaning. Third, a WF solution shares the main advantage of NAnt and MSBuild, the build scripts can be simple XML files. To be fair it does currently depend on Visual Studio being installed, although I'm sure I could build projects using the C# compiler directly (probably taking advantage of the MSBuild API in fact!).

So after a couple of hours work I had a few activities, a designer and a command-line application to run the workflow XOML (see my previous post) and a working build system. OK, I still have some tidying up to do but I was amazed at what I'd managed to achieve. After some more work I'll dump my code somewhere for people to play with.

Another take on this may be to use the WF designer to generate NAnt and MSBuild XML files directly. My understanding is that WF provides support for using your own custom DSLs. Something else to look at...

Update – You can now download the source code here. The only warranty that comes with it is that “it works on my machine”. In fact it’s quite possible it won’t work on your machine since some of the locations are hardcoded. There are four projects, one is the workflow designer control, then there is a GUI application that uses that control, there’s an assembly full of activities (some of which could be useful in other workflows) and finally there is a console application that can be used to run your build from the command line.

7 comments:

Anonymous said...

Very interesting. I was thinking of doing the same thing actually. NAnt and MSBuild can get pretty hairy and convoluted for big scripts and a visual flow is a cool way of representing builds. How far did u get with this?

Doogal said...

I've been using it for my personal projects pretty successfully. I like it a lot. Some of the activities are hardcoded to use the configuration of my machine so it's not exactly reusable. Hopefully some day I'll get round to actually fixing that and uploading the bits somewhere. Not enough time currently unfortunately.

Anonymous said...

Hey, why not use WF to create a designer that outputs either NAnt or MSBuild projects?

Doogal said...

That's a nice idea, I might give that a go at some point. I don't know much about MSBuild and haven't used NAnt for a good few years but it should be possible I think.

Anonymous said...

You mentioned that you would throw up the code and the results from your attempt to substitute msbuild with WF. I couldnt find any posts. Could you redirect me to the page ?

Thanks

Doogal said...

I never did get round to it. Thanks for reminding me though, I'll upload what I have got soon, promise. I never did look at generating MSBuild scripts though and some of my activities still use hardcoded paths but it may be useful to someone.

Anonymous said...

Thanks Doogal. Trying to get an idea of how you did it.