Nice programing

Bin Path는 어떻게 얻습니까?

nicepro 2020. 11. 9. 20:58
반응형

Bin Path는 어떻게 얻습니까?


실행중인 어셈블리의 bin 경로가 필요합니다. 어떻게 얻습니까? Bin / Debug에 폴더 플러그인이 있고 위치를 가져와야합니다.


응용 프로그램의 실행 경로를 얻는 방법은 다음과 같습니다.

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

MSDN에는 실행 응용 프로그램의 경로를 확인하는 방법대한 전체 참조가 있습니다.

의 값 path은 형식이 file:\c:\path\to\bin\folder되므로 경로를 사용하기 전에 file:\앞면 을 제거해야 할 수도 있습니다 . 예 :

path = path.Substring(6);

당신은 이것을 할 수 있습니다

    Assembly asm = Assembly.GetExecutingAssembly();
    string path = System.IO.Path.GetDirectoryName(asm.Location);

이것이 내가 이것을 달성하기 위해 사용한 것입니다.

System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, System.AppDomain.CurrentDomain.RelativeSearchPath ?? "");

var assemblyPath = Assembly.GetExecutingAssembly().CodeBase;

Path.GetDirectoryName(Application.ExecutablePath)

예. 값:

C:\Projects\ConsoleApplication1\bin\Debug

var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)?.Replace("file:\\", "");

참고 URL : https://stackoverflow.com/questions/3461865/how-do-i-get-bin-path

반응형