Here is the most universal way:
string exePath =
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetEntryAssembly().Location);
Other methods either require a library which you don't use (such as
System.Windows.Forms
) or depends on how the code is hosted (for example, using parameters of
Main
is not reliable).
—SA