1
하나의 폴더에 XML 파일이 포함 된 C# 클래스 라이브러리 프로젝트가 하나 있습니다. 프로젝트에서 이러한 XML 파일을 사용하고 싶지만 코드에서 XML 파일 경로를 가져올 수 없습니다.클래스 라이브러리 프로젝트에서 Xml 가져 오기
하나의 폴더에 XML 파일이 포함 된 C# 클래스 라이브러리 프로젝트가 하나 있습니다. 프로젝트에서 이러한 XML 파일을 사용하고 싶지만 코드에서 XML 파일 경로를 가져올 수 없습니다.클래스 라이브러리 프로젝트에서 Xml 가져 오기
xml 파일을 라이브러리에 포함시킵니다.
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "com.example.resource.xml";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
}
감사의 말 Arjun, 해결책이 효과적입니다. – Chirag