views:

76

answers:

3

While I'm working on it, I have my application's location hardcoded:

public static string MYPROGRAM_PATH = "/path/to/my/workspace";

Obviously this won't work once I package and distribute my application. How do I keep track of where it is installed to?

I'm primarily concerned with linux packaging (specifically .deb's), but I'm planning on using this as an exercise to learn about Windows and Mac packaging as well, so all tips are welcome.

+1  A: 

There are a number of ways to determine install/run locations in .NET

Environment.CurrentDirectory

will get the current working directory.

If you have installed the application to a specific location in Program Files, you can use:

Environment.SpecialFolder.ProgramFiles;

I'm almost positive there is a number of other ways to find out the current running path.

In terms of Linux, I'm assuming that this will be running under Mono? If so, I'm not sure exactly how they handle the special folders.

Enjoy!

Alastair Pitts
+1  A: 

If you want the path to the program's .exe, at least in Microsoft's .NET that's System.Reflection.Assembly.GetExecutingAssembly().Location (or Path.GetDirectoryName(...) if you want the directory) I believe this has been in .NET since 2.0 or before, so Mono should be compatible here (just checked, and it's included in the Mono documentation at least).

Max Strini
+1  A: 

If you're going to package your software inside a deb (or maybe rpm) package, why not just have the package install your program in /usr/bin, or if you're not comfortable with that, install it in /usr/local/bin. Then you don't have to play 20 questions as to where your program is located. Take a look at the man page for "hier" for more details on where files should be installed on the file system.

Johnny