views:

162

answers:

2

Hi All,

I have a relatively small app that Im building using vb.net 2.0, and nant. Its a app that calls out to an external exe to produce some output files, then processes those output files afterwards.

I have built an interface to the exe, which I have created a stub implementation and the real implementation, what I would like to be able to do is use nant to either create a DEBUG build of the app, which calls the stub implementation, or create a PROD build of the app which will use the correct implementation.

How could I achieve this?

Also, I do not have the ability to update to a newer version of .net, just so you know :)

Thanks! Mark

+3  A: 

Have you thought of using the #if DEBUG preprocessor directive? You could do something like the following:

object myDependency;
#if DEBUG
myDependency = new Stub();
#else
myDependency = new Actual();
#endif

Just a thought, but if its a relatively small application, it is a nice, simple solution that doesn't require a lot of hassle. When you build your Debug profile, the DEBUG compiler option is automatically set. When you build your Release profile, the DEBUG compiler option is absent. In anything other than a simple app, I would say use an IoC framework...like Ninject. Its nice and simple, lightweight...should work well for smaller applications.

jrista
not a bad idea, I will probably do that for now, considering it is a small app
Mark
Does anyone actually have an reference material I could read that can show me how to do DI with nant? Like for running unit tests, prod/dev builds etc? I cant seem to find much on it.
Mark
(meant to add this as a comment, not an answer) Yep, #if DEBUG is your friend. Especially when working with the web and having multiple website versions (development, staging, and production).
eduncan911
I would think the easiest way to do DI with something like Nant, or MSBuild, would be to use a configurable IoC framework like Castle Windsor, and use Nant to either modify the IoC config file or choose a one from a set of possibles. DI is really a coding concern, not a building concern...it would likely lead to some annoying problems if you tried to do it specifically with NAnt. There are lots of good existing IoC frameworks...I would recommend taking advantage of them, and use Nant for what it does best (and I'm certain there are nant extensions to support config modifications.)
jrista
I agree that nant is a build tool, but Im the kind of developer that like having things in one place. But I guess that I could have a testing config file and a prod one too.
Mark
I will mark this is the correct response as, it does solve my overall issue for now.
Mark
A: 

There's a bunch of DI frameworks out there and more coming. None of them however (of the ones I know) are "build tools". If you need someting fast something like Funq(1) would do nicely or ProS(2) when it's done

you might wanna read Daniel Cazzulino's blod on Funq(3) where he benchmarks several DI's

I would have linked above but am not yet allowed

Rune FS