views:

137

answers:

3

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'

+1  A: 

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

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

J c
are you saying put the XML file in this project as well?
ooo
I was assuming you had already moved it into that project, resulting in the copy operation not copying anything.
J c
+4  A: 

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.

Jon Skeet
Select Copy-Always to have it copied to the bin directory. That solve the problem
Tigraine
ok . .thats fine but i still need to access it from the other project
ooo
Is the file specific to your unit tests? (i.e. it's only used for mock data or similar, within the unit tests) If that's the case, it should go with your unit test project instead of the main project.
GalacticCowboy
no. . this data is needed for the regular project as well as the unit test
ooo
A: 

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

TT