C# Executable Executing directory

前端 未结 8 1992
庸人自扰
庸人自扰 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:00

    If the assembly has been shadow copied then Assembly.Location will point to the shadow copy of the dll.

    If you want to know the location of the build output directory use Assembly.CodeBase, i.e.:

    Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)
    

    Useful if you want to access other resources from the directory of the assembly for example when running test suite.

提交回复
热议问题