Conditional build events

  • Thread starter Thread starter Andrew Ducker
  • Start date Start date
A

Andrew Ducker

I've got a C# project that automatically kicks off NUnit whenever I do
a build. I want to change this so that it only does so when I've got
the Configuration set to NUnit.


Is there any way to either set up the post-build event to be
conditional, or have it be dynamic?


Cheers,


Andy D
 
Andrew Ducker said:
I've got a C# project that automatically kicks off NUnit whenever I do
a build. I want to change this so that it only does so when I've got
the Configuration set to NUnit.


Is there any way to either set up the post-build event to be
conditional, or have it be dynamic?

The way I do it, is in the project settings for your DLL, and with your
NUnit configuration selected, set the Debug Mode to 'Program', then set the
Start Application to 'NUnit-GUI'. You can specifiy command line arguments
separately to load the correct assembly and run it automagically.

If you really want to do it from a post build step, there is a
ConfigurationName macro, can you not use that with the standard bat file IF
conditional?

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
 
Aaaa, that would be great, if my project wasn't an EXE that I actually
wanted to run a fair bit of the time.

I shall go dig around and find out how IF works in .bat files...

Cheers,

Andy D
 
The other option is to using compiler directives to exclude the unit
test code unless you have selected the Unit Test configuration.
e.g.
#if UNITTESTS

<<test code>>

#endif

This way the Nunit console will run everytime but it will not have any
work to do unless UNITTESTS is set so will not impact build performance
too much when you don't want to be running the unit tests.

The problem with using a batch file as I see it is that its pretty hard
to tell visual studio when the Unit Tests failed. As the batch file
will always run successfully.

The other advantage of using a compiler directive is that you can then
not include your Unit Test code in your release binaries.

Cheers
Ian
 
The problem with using a batch file as I see it is that its pretty hard
to tell visual studio when the Unit Tests failed. As the batch file
will always run successfully.

You can run nunit-gui from the batch file, making failures more visible. If
you really want to run the console version, you could write a dinky little
tool that parse the output xml file and pops a message box if there are any
failures - or maybe it could launch NUnit-GUI if there are any problems.

I guess just running NUnit-GUI to start with is probably the best bet..

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
 
Back
Top