Get the startup path in a vb.net console exe

后端 未结 3 1961
半阙折子戏
半阙折子戏 2021-01-05 19:06

How do get the startup path ( system.windows.forms.application.StartupPath ) of my exe without adding a reference to system.windows.forms?

3条回答
  •  半阙折子戏
    2021-01-05 19:14

    EDIT: @KiwiBastard's answer is the correct method:

    System.AppDomain.CurrentDomain.BaseDirectory
    

    Add a reference to System.Reflection and use

    Assembly.GetExecutingAssembly().Location
    

    EDIT: Depending where you intend getting the startup path, this might be more appropriate:

    Assembly.GetEntryAssembly().Location
    

提交回复
热议问题