I have two apps that share a data files folder. One is an asp.net core web app. The other is a .net core console app. Folder structure is:
  WebApp
  WorkflowApp
  Datafiles
If I use any of these in the console app:
  string en = Environment.CurrentDirectory;
  string dr = Directory.GetCurrentDirectory();
  string ad = AppDomain.CurrentDomain.BaseDirectory;
  string sa = System.AppContext.BaseDirectory;
they all point to: workflow\bin\Debug\netcoreapp2.0
If I use them in the webapp, then en & dr point to "webapp" and the others point to "webapp\bin\Debug\netcoreapp2.0
I'm using appsettings.json to set the path to Datafiles. This file is shared by WebApp and WorkflowApp. I was setting it to "../Datafiles" and then getting the full path using:
  Path.Combine(Directory.GetCurrentDirectory(), datafiles);
But this only works in WebApp. I would like to find a common method that works for both. And I don't want to set an absolute path in appsettings.json.
I could use AppDomain.CurrentDomain.BaseDirectory and then use:
  @"..\..\..\..\Datafiles"
to move back from a "bin\Debug\netcoreapp2.0" folder. But this seems a bit convoluted. Is there a better way?
EDIT: An answer to this question might solve my problem (at least when in development): How can I get the path to the project folder (where the .csproj file is located) from in the code?
 
     
    