How can I get the application's path in a .NET console application?

后端 未结 27 1407
甜味超标
甜味超标 2020-11-21 11:11

How do I find the application\'s path in a console application?

In Windows Forms, I can use Application.StartupPath to find the current path, but this d

27条回答
  •  感动是毒
    2020-11-21 11:48

    If you are looking for a .NET Core compatible way, use

    System.AppContext.BaseDirectory
    

    This was introduced in .NET Framework 4.6 and .NET Core 1.0 (and .NET Standard 1.3). See: AppContext.BaseDirectory Property.

    According to this page,

    This is the prefered replacement for AppDomain.CurrentDomain.BaseDirectory in .NET Core

提交回复
热议问题