2013-06-18 4 views
9

다른 어셈블리의 기능을 사용하는 Web.Api 응용 프로그램이 있습니다. 이 어셈블리에서는 일부 문자열을 저장하는 .config 파일을 만들었습니다.dll.config가 임시 asp.net 파일 폴더에 복사되지 않았습니다.

나는 그 문자열 중 하나 페치 다음 코드를 사용하고 있습니다 : 임시 asp.net 파일에

private static string LogUrl = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location).AppSettings.Settings["WebApi-LogUrl"].Value.ToString(); 

Assembly.GetExecutingAssembly().Location 점을, (C : \ WINDOWS \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Temporary ASP.NET Files \ root \ dc2fa3d4 \ 834ee436 \ assembly \ dl3 \ cd068512) dll.config 파일은 여기에 복사되지 않습니다. 그 결과는 내 응용 프로그램을 디버깅 할 수 없으며 실제 IIS 서버에서 코드를 실행할 때 null을 제공합니다.

설정을 가져 오기 전에 중단 점을 설정하면 임시 폴더를 확보 할 수 있고 거기에 내 dll.config 파일을 복사하면 작동하지만 어떻게 자동으로 수행해야합니까?

내가로 설정 내 dll.config 파일의 속성이 "조치를 빌드 : 내용을", "출력 디렉토리에 복사 : 항상"

어떤 도움을 주시면 감사하겠습니다, 지금 시간 동안 검색 좀. !

// The dllPath can't just use Assembly.GetExecutingAssembly().Location as ASP.NET doesn't copy the config to shadow copy path 
var dllPath = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; 
var dllConfig = ConfigurationManager.OpenExeConfiguration(dllPath); 

// Get the appSettings section 
var appSettings = (AppSettingsSection) dllConfig.GetSection("appSettings"); 
return appSettings.Settings; 

열쇠가 : :(

안부, 피터 라르손

답변

17

나는 다음과 같은 코드를 사용하여이 문제를 해결

new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath 

나는 그와 함께했다 솔루션 읽기 후 Zhaph - Ben Duguid의 대답 : https://stackoverflow.com/a/2434339/103778.

이제 웹 응용 프로그램의 bin 디렉토리에있는 DLL의 구성 파일을 선택할 수 있습니다.

나는이 이후로 더 written up a blog post을 가지고 있습니다.

+0

아하, 이것 좀 봐야 겠어. 제안 해줘서 고마워! –

+0

나를 위해 일했습니다. 팁 고마워! –

+0

이것은 많은 도움이되었습니다. 또한 CodeBase 속성이 Assembly 클래스의 속성이기 때문에 GetName()에 대한 호출이 쓸모없는 것으로 나타났습니다. – sluki

관련 문제