All the solutions I've found for getting the path of the current file do not work in two situations: when running unit tests from another project in the solution, and when accessing the project from another project with a reference.
When running unit tests, the path generated by these are all relative to the Test project in my solution, and this causes the path I'm building to access some assets to be incorrect:
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
System.AppDomain.CurrentDomain.BaseDirectory;
System.Environment.CurrentDirectory;
System.IO.Directory.GetCurrentDirectory();
Environment.CurrentDirectory;
Thread.GetDomain().BaseDirectory;
Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
System.IO.Path.GetFullPath(@"..\..\");
They all output the wrong project when running unit tests: C:\Users\Me\source\MySolution\TestProject\bin\Debug
I need it to output the same path to the correct project:
C:\Users\Me\source\MySolution\CoolProject\classes\somefile.cs
or
C:\Users\Me\source\MySolution\CoolProject\classes
or
C:\Users\Me\source\MySolution\CoolProject\
or
C:\Users\Me\source\MySolution\CoolProject\bin\debug
How to generate a path to the current file or at least the project that the code resides within?