views:

74

answers:

1

I have some files I want to use in my unit tests but I want to make those files relative to location of the dll which contains the unit tests, is this possible?

In other words I have included a Resources folder which contain some files for my unit tests to use in testing, I marked the files "Build Action" = "Content" and "Copy to Output Direct" = "Copy Always" but that isn't doing what I thought it would do. I thought it would copy the content along, but when my tests run, they say the files do not exist.

I would prefer to not resolve this by putting explicit paths, because these paths would then vary from developer machine to developer machine.

I also tried adding the following as a Pre-build event and also as a Post-build event, but that didn't solve my problem either.

xcopy "$(ProjectDir)Resources\*.*" "$(OutDir)Resources\*.*" /i /d /s /y

If I make the previous a pre or post build event I see that the data is copied to my outdir, but it doesn't make it to the TestResults folder which is where the Resources folder must also be copied for the tests to have any data to tests.

+2  A: 

The unittest runner must be copying your unittest assemblies to some temp folder. Instead of copying those resource files, consider including them as Embedded Resources and then loading them from assembly using Assembly.GetManifestResourceStream().

Anton Gogolev
Thanks! This solution wasn't exactly how I thought I'd go about it, but it works.
Dave