본문 바로가기

C#/예제 코드

c# config 파일 경로 바꾸는 2가지 방법.

사전지식

그냥 내버려두면 debug 폴더 따로, release 폴더 따로 저장된다. 

특정 위치에 하나만 두고 글로발 하게 사용하고 싶을 떄 2가지 방법이 있는 거 같다. 


실습

1.

var config =  ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap(){ExeConfigFilename = SomePath + "/App.config"}, ConfigurationUserLevel.None);
 

 

2.

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", SomePath + "/App.config");
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

여러 개의 config 파일을 로드하고자 할 때 1번, 하나만 쓸 거면 2번으로 가는 게 적당할 것 같다.