How do I get the path of the assembly the code is in?

前端 未结 30 2761
小蘑菇
小蘑菇 2020-11-21 16:17

Is there a way to get the path for the assembly in which the current code resides? I do not want the path of the calling assembly, just the one containing the code.

<
30条回答
  •  灰色年华
    2020-11-21 17:14

    Starting with .net framework 4.6 / .net core 1.0, there is now a AppContext.BaseDirectory, which should give the same result as AppDomain.CurrentDomain.BaseDirectory, except that AppDomains were not part of the .net core 1.x /.net standard 1.x API.

    AppContext.BaseDirectory
    

提交回复
热议问题