How to get the executable path from a Managed DLL

懵懂的女人 提交于 2019-12-05 17:24:16
Assembly.GetCallingAssembly()

or

Assembly.GetExecutingAssembly()

or

Assembly.GetEntryAssembly()

Depending on your need.

Then use Location or CodeBase property (I never remember which one).

Brian Stewart

@leppie: Thanks - that was the pointer I needed.

For future reference, in C++/CLI this is the actual syntax that works:

String^ appPathString = Assembly::GetEntryAssembly()->Location;

GetExecutingAssembly() provided the name of the DLL

GetCallingAssembly() returned something like System.Windows.Forms

GetEntryAssembly returned the full path, similar to GetModulePath() under Win32.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!