developer tip

내 프로젝트 경로를 얻는 방법?

copycodes 2020. 12. 27. 11:16
반응형

내 프로젝트 경로를 얻는 방법?


중복 가능성 :
C #을 사용하여 내 .exe 경로 가져 오기

안녕하세요 질문이 있습니다. 루트 프로젝트 경로를 어떻게 얻을 수 있습니까? 내 말은 솔루션이있는 프로젝트의 첫 번째 폴더입니다. 그 명령을 찾았습니다.

System.IO.Directory.GetCurrentDirectory();

그러나 릴리스 폴더에 대한 특정 경로를 제공합니다. wanted_Path / bin / Release

다른 코드가 있습니까? 수동으로 잘라내거나 Release 폴더에 파일을 넣어야합니까?


당신이 사용할 수있는

string wanted_path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));

이렇게하면 루트 폴더가 제공됩니다.

System.AppDomain.CurrentDomain.BaseDirectory

여기에서 .. 또는 ./ 등을 사용하여 탐색 할 수 있습니다.. .. 추가하면 .sln 파일이있는 폴더로 이동합니다.

.NET 프레임 워크의 경우 ( Adiono 의견 덕분에 )

Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"..\\..\\"))

.NET 코어의 경우 여기에 방법이 있습니다 ( nopara73 주석 덕분에 ).

Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..\\..\\..\\")) ;

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

프로그램은 VS 프로젝트가 어디에 있는지 알지 못하므로 내 .exe 경로 가져 오기를 참조 하고 ../..프로젝트 경로를 가져 오십시오.

참조 URL : https://stackoverflow.com/questions/14549766/how-to-get-my-project-path

반응형