Search code examples
c#linuxubuntudebianpackaging

What's the simplest way to keep track of where my program is installed?


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.


Solution

  • 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!