Melody
Melody

Reputation: 1203

AppDomain.CurrentDomain.BaseDirectory returns unit test project root location instead of source project

In my application project i have used AppDomain.CurrentDomain.BaseDirectory to get the file path. When i include the unit test in my project, the AppDomain.CurrentDomain.BaseDirectory returns unit test project directory instead of my source project while debugg. Can you please let me know how to resolve this issue?

Thanks.

Upvotes: 3

Views: 3536

Answers (2)

OrganicCoder
OrganicCoder

Reputation: 117

Default setting point to bin\debug folder in Visual studio 2010 test projects. But if you enable deployment option of Edit test settings, AppDomain.CurrentDomain.BaseDirectory points to the TestResults\Out folder. I have added unit test project first, later with additional projects.

Joe, can you provide link from MSDN to support your expected behaviour answer?

I would suggest to read this answer for referring to the location where your assembly resides. https://stackoverflow.com/a/8670008/2611808

Upvotes: 0

to StackOverflow
to StackOverflow

Reputation: 124794

That's the expected behaviour.

You could consider copying the required files to the unit test directory.

In Visual Studio 2010, look at "Deployment" under "Test Settings".

Upvotes: 1

Related Questions