1. 사용하고자 하는 dll을 프로젝트에 참조
2. 해당 dll을 프로젝트 리소스에 추가
3. 리소스에 추가된 dll의 속성 -> 빌드작업 속성 값을 포함 리소스로 지정
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main() {
// 리소스 dll 취득
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ResolveAssembly);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
// 리소스 dll 취득
private static System.Reflection.Assembly ResolveAssembly(object sender, ResolveEventArgs args) {
System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly();
string name = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";
var files = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(name));
if (files.Count() > 0) {
string fileName = files.First();
using (System.IO.Stream stream = thisAssembly.GetManifestResourceStream(fileName)) {
if (stream != null) {
byte[] data = new byte[stream.Length];
stream.Read(data, 0, data.Length);
return System.Reflection.Assembly.Load(data);
}
}
}
return null;
}
[C#] Thread Synchronization C#스레드 안전화의 모든것 (0) | 2023.07.27 |
---|---|
[C#] Form 폼 최소화버튼 막기 (0) | 2023.07.25 |
[C#] 일반화 프로그래밍 (0) | 2023.07.25 |
[C#] 컬렉션 Collection (0) | 2023.07.25 |
[C#] 프로퍼티 (0) | 2023.07.25 |