0
votes

I used to have a Tests folders in my main project where a unit test had this line of code:

Foo foo = new Foo(Environment.CurrentDirectory + @"\XML\FooData.xml" );

I have an XML directory in the Foo project that has a FooData.xml

In the post build event of my projects i have the following line copy "$(ProjectDir)Foo\Currencies.xml" "$(TargetDir)\XML"

I now have broke all unit tests into another projects to separate them out and i now get the following error when running these unit tests.

Could not find a part of the path 'C:\svncheckout\Foo.Tests\bin\Debug\XML\FooData.xml'

3
Just as a little aside, use System.IO.Path.Combine() instead of string concatenation for paths where possible...Dave Markle

3 Answers

4
votes

Rather than having a post-build step, can you not just make it a "content" item in Visual Studio, telling it to copy it to the target directory? I usually either do that, or make it an embedded resource and use streams and Assembly.GetManifestResourceStream.

1
votes

I believe you need to update the post build event for the Foo.Tests project to be:

"$(ProjectDir)Foo.Test\Currencies.xml" "$(TargetDir)\XML"

0
votes

You can also put the full path of the xml in your test modules app.config