samedi 9 janvier 2016

Get the real startup path in Mono C# CLI application

I need to retrieve the full path (up to directory) of the application's binary file. It is a CLI application that I test on OSX, suppose it resides at /usr/local/bin/.

The matters are further complicated 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 (or Assembly.GetEntryAssembly().CodeBase). 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.





Aucun commentaire:

Enregistrer un commentaire