How do I get Bin Path?

后端 未结 6 1422
时光取名叫无心
时光取名叫无心 2020-12-25 09:32

I need to the the bin path of the executing assembly. How do you get it? I have a folder Plugins in the Bin/Debug and I need to get the location

相关标签:
6条回答
  • 2020-12-25 09:47

    You could do this

        Assembly asm = Assembly.GetExecutingAssembly();
        string path = System.IO.Path.GetDirectoryName(asm.Location);
    
    0 讨论(0)
  • 2020-12-25 09:53
    Path.GetDirectoryName(Application.ExecutablePath)
    

    eg. value:

    C:\Projects\ConsoleApplication1\bin\Debug
    
    0 讨论(0)
  • 2020-12-25 09:56
    var assemblyPath = Assembly.GetExecutingAssembly().CodeBase;
    
    0 讨论(0)
  • 2020-12-25 10:01

    Here is how you get the execution path of the application:

    var path = System.IO.Path.GetDirectoryName( 
          System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
    

    MSDN has a full reference on how to determine the Executing Application's Path.

    Note that the value in path will be in the form of file:\c:\path\to\bin\folder, so before using the path you may need to strip the file:\ off the front. E.g.:

    path = path.Substring(6);
    
    0 讨论(0)
  • 2020-12-25 10:02

    This is what I used to accomplish to this:

    System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, System.AppDomain.CurrentDomain.RelativeSearchPath ?? "");
    
    0 讨论(0)
  • 2020-12-25 10:06
    var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)?.Replace("file:\\", "");
    
    0 讨论(0)
提交回复
热议问题