App.config Files

Kiwidude asked a question about how 'app.config' files are handled.

How do use your add-in with app.config files now? With the 'previous version' I managed a 'bodge' of creating one in my test project bin directory called 'NUnitAddin.TestRunner.Server.exe.config', and copying the contents of my 'real' app.config into that. Ugly but only way I could get it to work. Now this no longer works (you seem to be creating random appdomain config files in temp directory)... Can you please explain how we get it to work ?

NUnitAddin has supported config files for a long time. It intentionally handles them in a similar way to NUnit. The last thing you want is tests working in NUnitAddin but failing with NUnit (or the other way around). When NUnit creates a new app domain it looks for a config file with the same name as the test assembly but ending with '.config'. This is convenient if the test assembly is an EXE project because Visual Studio with automatically rename and copy 'app.config' files into the project output directory. If however the project you're working on is a DLL project, you will have to do this yourself as Visual Studio won't help you out.

It would be easy for NUnitAddin to help out here and copy 'app.config' files for library projects as well. I have been a bit reluctant to do this so far the following reason. If you're using a tool such as CruiseControl.NET for Continuous Integration you will have to make sure the '.config' file is copied as part of the build. In the past I have found it tricky enough mirroring everything that Visual Studio does in the build script. If NUnitAddin started doing this is would be one more thing to remember. If you still want the 'app.config' file automatically copied for your test projects there is an easy solution. Just make your tests and EXE project and Visual Studio will do your dirty work. ;)

2 Comments

  • Thanks mate, the penny finally dropped for me on this one for a solution based on the above. I switched my test projects to executables instead of dll libraries, then added my App.config as a 'linked file' in VS.Net to each of my test projects. No more multiple edits of config files required or batch copying to avoid out of synch problems... stupidly simple in the end... doh...



    Unfortunately a bug exists in the latest NUnit 2.19 framework standalone GUI which means this solution currently only works with the NUnitAddin... (or NUnit GUI v2.14). A simple tweak to the source code for the NUnit GUI (to call the Load overload with a configurationFile parameter) fixes that and as the bug is listed a couple of times on the SourceForge forums hopefully that will be addressed soon...



    Great stuff!

  • Hey I just found this. Maybe that's why I was so far off-base in commenting on the followup to this post! :)

Comments have been disabled for this content.