NCrunch Project Build Issues / by James Heywood

Hello all, it's been a while since the last post, mainly because I couldn't think of what to post about. I have a few bits and pieces on the go but nothing complete enough to warrant a post, so instead I did nothing! However I had a thought the other day, the next time I find a fix to a problem I'm having with something technical at work I can post about that, as it's a good way of documenting a fix for others who may be having the same issue and it also means I have something to say!

So today I have been setting up NCrunch, to help monitor test coverage of the project I'm currently working on. If you're not aware of NCrunch head on over to their site as it's a great piece of software to assist your TDD. It takes away the pain of compilation/build and let's you focus on the more productive parts of TDD, like writing tests and meeting them in the code/system under test, i.e. the bit we want to be doing as developers!

Anyway, I had fun setting up the projects initially as NCrunch just wouldn't load one of my unit test projects, the error message received was the old classic "could not load file or assembly", specifically referring to Newtonsoft.Json.dll in my case. After a spot of reading of the NCrunch documentation site I came across this page suggesting that the project build issue I was experiencing was due to implicit file/build dependencies.

Briefly, NCrunch works asynchronously testing your code as you write it, which is great, in order to do this though it has to copy the related assemblies and resources needed by the code you are testing to a working folder for it's own compilation and execution and it is this that was causing my issue.

There are several suggested fixes, however the least intrusive in my opinion was to use the Additional files to include configuration setting, this seemed a safer option than hacking the .proj file of the test assembly.

To do this I went to the NCrunch menu in Visual Studio, selected Configuration, then selected my troublesome project. In the General section of the project configuration I then clicked the small ellipsis button in the Additional files to include setting and selected the offending DLL (and related XML file) for Newtonsoft.Json and then clicked OK.

NCrunch then displayed a warning; "NCrunch detected unusual behaviour around the resolution of referenced assemblies required by this project in its test environment...." and so on, which I hastily ignored. You can view this and any other warnings through the NCrunch Test window at any time, so don't be worried about skipping over a warning like this if you are following this yourself.

After this all I then needed to do was to disable and re-enable NCrunch from the NCrunch menu in Visual Studio et voila I am now crunching tests, sweet!

So there you have it, hopefully that is of some use to someone out there, if so let me know.