I have a situation where I am running a unit test and trying to get the project base path and it is giving me a odd output.
D:\VSCode\Bob.Smith\Projects\MySolution\DEVELOPMENT\MyClasses\MyProject\TestResults\Jacob.Freeman_P1004 2012-11-26 09_21_33\Out
Is this a known issue with VS or just something that I have missed out? I am using the following line with no other code to get the directory information.
string output = null;
output = Environment.CurrentDirectory;
I have tried different various ways to get the directory information such as the following, but it still gives me the same output.
output = System.IO.Directory.GetCurrentDirectory()
Thanks in advance.
As documentation states
Environment.CurrentDirectory:The current working directory is not necessarily the projects base path – It is when you start an exe. While running test this path is set by test runner. This variable can change while program is running.
In application you should use
Assembly.GetEntryAssembly().Locationto get location of you exe file. This will not work for tests as they are executed by test runner.If for test purposes you simply need location of tested dll file you can use
typeof(SomeTypeThatIsDeclaredInThatDLL).Assembly.Location.