I am trying to register my executable for some shell action and need to find out the path to current executable. I found several questions (and answers) here on SO, and found the following options:
Environment.GetCommandLineArgs()[0]
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
typeof(Program).Assembly.Location
However when debugging inside Visual Studio 2010 the first two return the vshost exe name, e.g. ...bin\Debug\ExportVSProject.vshost.exe
. I think I understand why. By trial-and-error I found that the last provides the right name inside VS and outsid开发者_JAVA技巧e.
My question is, are there any downsides to using Assembly.Location
? The reason I am asking is I did not see any comparison to choose one over the other in the other answers.
It's fine. The more general solution is Assembly.GetEntryAssembly().Location, usable anywhere.
精彩评论