Finding my main executable's path using Assembly vs AppDomain

后端 未结 5 685
面向向阳花
面向向阳花 2020-12-09 03:21

I\'m a .NET user, and my goal is as simple as finding the absolute path of the directory of my main executing assembly (the EXE file).

I have several candidates:

5条回答
  •  天涯浪人
    2020-12-09 04:02

    Unfortunately, all the methods above can fail if you use a virtualization like XenoCode postbuild. I have tested many methods and found another solution here. I've found that only the

    System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe"
    

    returns the correct filename of the executable. So combining the filename with the path from Assembly.GetEntryAssembly().Location you will get the correct path of the executable.

提交回复
热议问题