실행중인 어셈블리의 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.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
이것이 내가 이것을 달성하기 위해 사용한 것입니다.
System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, System.AppDomain.CurrentDomain.RelativeSearchPath ?? "");
RelativeSearchPath에는 실제 "bin"폴더가 포함되어 null있고 콘솔 앱에서는 BaseDirectory실제 "bin"경로가 포함되어 있습니다.
Path.GetDirectoryName(Application.ExecutablePath)
예. 값:
C:\Projects\ConsoleApplication1\bin\Debug