[MacOS] Console Application - Issue recognizing the file Path

Juan Gomez 20 Reputation points
2023-02-03T13:15:24.28+00:00

Dear community,

I have this issue: I deployed a console application (C# - Visual Studio - Unix Executable File). As you will see in the following screenshots, the issue is that running by double-click or using the full path doesn't allow the Terminal to recognize the Folder the file is in. Still, if I go to the folder first and then I run the application it works without issues.

I used these lines for seeing the console information. The result in Images 4 and 5:

var path = Directory.GetCurrentDirectory();
Console.WriteLine(path);

So my question is: what do I need to do in the code for forcing the MacOS terminal to recognize the current PATH where the executable is? I need to read the appsettings.json, and a masterdata.sv file from the directory.

[Image 1]: double-clicking it.

error file path double-clicking on it

[Image 2]: using the full file path.

[Image 3]: going inside the folder and running the Unix Executable File

[Image 4]: running Directory command debugging in the VS for MAC:

Image 4

[Image 5]: running by double-clicking the executable in the same Debug folder:

Screenshot 2023-02-03 at 8.12.32

Thanks in advance,

Juan

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,367 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,233 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.1K Reputation points
    2023-02-03T13:48:44.3133333+00:00

    Check this path:

     string f = Path.Combine( Path.GetDirectoryName( Assembly.GetEntryAssembly( ).Location), "appsettings.json" );
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful