I need to retrieve the full path (up to directory) of the application's executable file made using mkbundle --static
. It is a CLI application that I test on OSX, suppose the executable resides at /usr/local/bin/
.
The matters might be further complicated (but I don't really know) since I want to run the utility from any directory, so I add the above path to $PATH
environment variable (in this case, it is already there).
Now, suppose the application is launched while being at ~/dir1/dir2/
, and suppose it prints the Application.StartupPath
. That yields the path ~/dir1/dir2/
. In contrast, I want to always retrieve the real directory from which the application is launched, i.e. /usr/local/bin/
.
Is there any way to achieve this (preferably in a platform-independent way)?
I use Xamarin Studio configured with Mono/.NET 4.5 and C# 6.0.
UPDATE: Getting typeof(Program).Assembly.Location
also doesn't help much.
I mean, it works well when I just run the normal application executable (produced during the build process).
However, if I run a bundle made with mkbundle --static
, the Location
just gives the executable name App.exe
without any prior path.
Probably it just displays the relative path inside the bundle. Is there any way I can get the path to the bundle itself?..