Build/Test Issues

Referenced files not copied over, causing tests to fail.

Started by ChrisMcLean on 5,036 views

Right now in one C# library we have an xml file in the project. It is set to copy always in that project.

We have a test which uses that lib, and in the test's debug directory, there is a folder schema, and a file in that folder bob.xml that we are using to hold some info that is used in the library. The tests run fine in msft's test runner.

But nCrunch reports the test failing

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Chris\AppData\Local\NCrunch\119428\15\ScoreMessageTests\bin\Debug\Schema\bob.xml'.

Does anyone know of any workarounds?
Hi Chris,

I'm sure we can find a way to make this work. What is the origin of the bob.xml file? My assumption is that this is being sourced from somewhere else in your solution and that it is copied to the bin\Debug\Schema directory at build time. Is this correct?
Yes. In the Lib project there is a folder schema, and in that folder we've got bob.xml, set to always copy. In MSBuild this results in the Debug directory looking like:
\Debug
lib.dll
lib.pdb
etc...
\Schema\
bob.xml

The rational behind this was that we're eventually going to have bob1.xml, and bob2.xml, and just stick 'em in a folder so they don't get in the way.

In MSTest, when we reference the Lib project, we get the same folder structure in it's Debug directory, so the test runs fine.

Right. Because bob.xml is a direct dependency of the Lib project and not of the Test project, it's probably not being copied because of the limited scope of the 'Copy referenced assemblies to workspace' configuration setting. When you enable this setting, it will only apply to the project that you've enabled it for. Probably in this case we need to be a bit broader with where we specify it.

For the sake of narrowing things down, if you enable the 'Copy referenced assemblies to workspace' configuration setting for ALL the projects in your solution (use the multi-select option in the configuration window), does this solve the problem?

If at all possible, it may be worth looking at ways in which this file is referenced. If you're able to introduce an abstraction that lets you find the file at its source location (instead of the copied location) when the test is executed with NCrunch, this means you won't need to make use of the 'Copy referenced assemblies to workspace' setting and the engine will work much faster.

Post a reply

Log in to reply.