코드에서 configSource를 검색하는 방법이 있습니까? 나는 How to programmatically retrieve the configSource Location from config file를 설립했으나 모든 대답이 잘못되었습니다. 내가 다음 코드를 호출하려고코드에서 appSettings 구성 소스 가져 오기
<configuration>
<appSettings configSource="appsettings.config"/>
</configuration>
:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var file = config.AppSettings.File;
file
은 항상 비어
나는 다음과 같은 설정이있다. ConfigurationManager.AppSettings["configSource"]
도 마찬가지입니다. 대답은 오래된 것들이므로 .NET 4에서 뭔가 바뀌 었다고 생각합니다. config.AppSettings.SectionInformation.ConfigSource
도 시도했지만 비어 있습니다.
appSettings
의 모니터링을 사용하려면이 경로가 필요합니다. 너는 더 많은 것을 읽을 수 있었다 : How to discover that appsettings changed in C#?
이것을 사용하여 올바른 구성 파일을 반환하는지 확인할 수 있습니다. ConfigurationManager.OpenMappedExeConfiguration (새 ExeConfigurationFileMap {ExeConfigFilename = configurationFilePath}, ConfigurationUserLevel.None); – TYY
@TYY 예입니다. –
'ConfigSource' 속성이 작동하지 않았습니까? http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx –