C# Executable Executing directory

前端 未结 8 1980
庸人自扰
庸人自扰 2020-12-11 02:38

What is the best method of getting the path the C# executable is running from?

I need to use it for temp folders etc and currently I\'m using:

Path.G         


        
相关标签:
8条回答
  • 2020-12-11 03:18
    • .NET Core 3.0 introduced IHostEnvironment.ContentRootPath.
    • .NET Core 2.1 introduced IHostingEnvironment.ContentRootPath (obsolete since Core 3.0).

    Personally I find that these are what I generally need: the place where included content is located.

    I can confirm that IHostEnvironment.ContentRootPath also returns the desired result when running as a unit test. (Tested with xUnit, but the test framework should not matter.)

    0 讨论(0)
  • 2020-12-11 03:20
    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
    
    0 讨论(0)
提交回复
热议问题