Cory Foy

Wednesday, August 24, 2005

NUnit App.Config files - it's all about the .nunit file!

When you are running an assembly test in NUnit, you may need to access App.Config values. NUnit loads the App.config files by looking for a file with AssemblyName.config.

However, in the default configuration, that .config file has to be in the same directory as the .nunit project file. For example, we had the following setup:

\src\MyProject\MyProject.nunit
\src\MyProject\MyProject\MyProject.sln
\src\MyProject\MyProject\bin\debug


putting the MyProject.config file in either \src\MyProject\MyProject or in \src\MyProject\MyProject\bin\debug doesn't work - NUnit can't find it. Putting it in \src\MyProject works like a charm.

11 Comments:

  • You, sir, are an evil genius! I spent ages trying to fix a problem which was caused by this. Thanks :-)

    By Blogger Jack, at 10:35 AM  

  • I had this same problem and this fixed it. I was using NUnit to test the NHibernate section of my app and it couldn't find the App.config file. But I didn't know that.

    What I did was put my NUnit Project inside the bin folder. I also had to change the Properties for Configuration File NAme.

    By Blogger Praveen Angyan, at 3:27 AM  

  • Wow, that worked! Thanks a ton -- I wasted well over an hour trying to figure out why my App.config file was not being found.

    By Anonymous Anonymous, at 3:14 PM  

  • This helped me. Thanks.

    I found that I had to have my .config file in the same folder as the nunit file. Both had to have the same root name and since I quickly got tired of renaming project.dll.config to project.config, I decided to turn the problem on its head and name the nunit project file project.dll.nunit. It's been working fine ever since.

    I still don't like that I have to copy my config file up 2 levels just for nunit to work!!!

    By Anonymous Matt, at 8:19 PM  

  • Thanks !!!!

    You saved my life ^^

    By Anonymous Anonymous, at 10:20 AM  

  • Please note that the file [myDir]\[myApp].config will only be read if i start "nunit.exe [myDir]\[myApp].nunit"

    (the assembly-name does NOT MATTER.. worked for me like this with Nunit 2.4.)

    Hope this helps somebody...

    By Anonymous Rolf Schmidiger, at 3:27 AM  

  • Thanks for saving hours of work!

    By Anonymous Anonymous, at 5:02 AM  

  • You have saved my life! Many thanks.

    What a stupid way for Nunit to work!!!

    By Anonymous Anonymous, at 5:58 AM  

  • Here's another way.....

    If you have an NUnit-enabled project with a .config file, you could just open the assembly (.dll) in NUnit instead of the project (.vbproj or .csproj) or solution (.sln) file. It will find the .config file.

    By Anonymous Anonymous, at 11:20 AM  

  • Try this

    copy /Y "$(ProjectDir)App.config" "$(TargetDir)$(TargetFileName).config"


    in your Build Events of test project

    By Blogger Urmil Shah, at 5:13 PM  

  • Just another thank you -- my neck was getting sore from banging my head against the wall...

    By Anonymous Spencer, at 10:35 AM  

Post a Comment

Links to this post:

Create a Link

<< Home