1

In my C# .NET core solution, I have two projects, a BASE, and a TEST project. The TEST project references BASE and BASE has a method that needs to use a file from BASE's output folder. Even when TEST is calling the method from BASE, it needs to point to BASE's output directory.

However, when executing the test from the TEST project (which uses the methods from BASE), all the methods I can find point to TEST's output directory, not BASE's. Any tips/ideas?

Here is a list of methods I have tried. These are being executed within BASE, but being called from TEST.

var t1 = AppDomain.CurrentDomain.BaseDirectory;
var t2 = Assembly.GetExecutingAssembly().Location;
var t3 = Environment.CurrentDirectory;
var t4 = Assembly.GetCallingAssembly().Location;
var t5 = Assembly.GetEntryAssembly().Location;
var t6 = Assembly.GetExecutingAssembly().GetName().CodeBase;
var t7 = Assembly.GetCallingAssembly().GetName().CodeBase;
var t8 = Assembly.GetEntryAssembly().GetName().CodeBase;
var t9 = System.IO.Directory.GetCurrentDirectory();
var t10 = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName;

As you can see below, each of these points to the TEST's directory, not the BASE project's directory where the file needed resides. enter image description here enter image description here

Thank you in advance!

Ned
  • 490
  • 4
  • 15
  • Does this answer your question? [How do I get the path of the assembly the code is in?](https://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in) –  Jun 02 '21 at 21:34
  • 1
    _"The TEST project references BASE and BASE has a method that needs to use a file from BASE's output folder"_ - have you tried to [change file type](https://stackoverflow.com/a/16785426/2501279) to `Content` and build action to `Copy Always/Copy if newer`? – Guru Stron Jun 02 '21 at 21:34

0 Answers0