If you use NAnt for your build scripts, colored console output may be helpful in quickly spotting warnings or errors. I recently wrote a logger to do that:
- Download the source for the version of NAnt you're using (I tested this against NAnt 0.85).
- Apply this patch to the source tree. If you're on Windows, I believe you can use 'patch.exe' which comes with UnxUtils.
- Build NAnt by following the instructions in 'README.txt'. This will produce a bunch of files, but the only one we're interested in is 'NAnt.Core.dll'.
- In the directory where you store your NAnt binaries (eg. on my current project, it's in MyCurrentProject/tools/nant), replace 'NAnt.Core.dll' with the new one.
- The last step is to add an option to your 'nant' call to specify the use of the new logger:
nant -logger:NAnt.Core.ConsoleColorLogger ...
On my current project, we have a 'build.bat' which invokes NAnt, so I just added the option there.
Customizing the colors
Simply specify additional properties when you invoke NAnt like this:
nant -logger:NAnt.Core.ConsoleColorLogger -D:ConsoleColorLogger.error=DarkRed -D:ConsoleColorLogger.warning=DarkMagenta ...
The levels you can customize are one of error/warning/info/verbose/debug. The colors you can use are 'default' (which means to use the foreground color you had before invoking NAnt) or one of these.
Hope that helps!
16 comments:
Hey Liuer,
Great post. Love NAnt in color.
Good to see you back into the blogging world.
Looking forward to hearing some more dev tips and tricks from a top coder such as yourself.
Cheers - JR
It also works with nant-0.86 beta 1.
Great!! I hope that you are working to get this integrated into the actual Nant codebase. I'll hope to see this in 0.86! Thanks, Tom
For people who doesn't want to compile the code. I have also created a colorizer for nant. The projects homepage is at http://colornant.googlepages.com/
Regards,
Albert Ritmeester
Is it correct that it only needs .NET 2.0 or higher to work? Coding isn't my strong suit so applogize if this is a silly question.
Don't suppose you could put the compiled dll up on your blog. It's not the easiest thing to have to create.
If not I'll give it another try tomorrow.
Ah no worries, got it working. Excellent post, now our "go.bat" output looks so much better.
how bout a frickin blog entry once in a while? :( :'D :::**&?
Hi Eric,
I have created a NAnt extension based on your NAnt color patch.
Please have a look at http://nantloggerext.sourceforge.net/
Best regards
Alex
Thanks for sharing this article on Software development. It was very nice.
Looking for more..................Please continue.
Hello,great post. Information are pretty exciting and saved me huge amount of time which I have spend on something else instead of searching posts like this. I am waiting for more.
Hi there,
Sorry for posting here - couldn't find your e-mail address.
I'm the leading editor of Software Developer's Journal which is a new e-magazine. I'm looking for developers who would like to share their knowledge with other developers. If you are interested in cooperation (articles writing, proofreading, ads) just please let me know - roger.zacharczyk@software.com.pl
Very valuable post. Thanks for sharing.
Nice post. This is exactly what I've been looking for. Thanks.
How about submitting it to NAnt so that it gets built in? Sadly it's still on SF and not something like GitHub but should still be simple given you've a patch.
Nice post. I learn something more challenging on different blogs everyday. It will always be stimulating to read content from other writers and practice a little something from their store. I’d prefer to use some with the content on my blog whether you don’t mind. Natually I’ll give you a link on your web blog. Thanks for sharing.
Post a Comment