开发者

several choices for executable path, but only one works inside Visual Studio?

开发者 https://www.devze.com 2023-04-09 18:23 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消