Search code examples
c#.netmstestxunitxunit.net

Runtime folder structure when running xUnit.net tests


I'm working on a C# web app running on .net 4.6.1 that assumes that certain dlls are in the same folder as the executing assembly and tries to import some types from those dlls using MEF. That works fine when the app is running and all the required dlls are in the bin folder, but I have problems when running xUnit tests that eventually get to run the code that makes the assumption mentioned above. I'm running the tests using Visual Studio 2017.

The problem I have is that when I run an xUnit test it creates a temp folder which contains a subfolder for each reference I have in my unit test project. In every subfolder there is the .dll and the .pdb file of a single reference along with an __AssemblyInfo__.ini file. Obviously, the test crashes with a FileNotFoundException because the code that wants to import some types using MEF cannot find the dlls in the same folder as the executing assembly location.

Is there a way to tell xUnit to put all the references of the unit test project in a single folder (like the bin folder?) and run the tests using that folder? Or is this maybe a setting in Visual Studio 2017?


Solution

  • You can simply disable shadowCopy, so that all execution uses your output folder.

    To learn how to configure xUnit.net via JSON, use a search engine.