C# 실행파일 안에 DLL 넣기
개발 중인 프로젝트에서 상용 컴퍼넌트를 이용하다보니 제작한 라이브러리 포함하여 dll이 30개 정도 되었다.
고객님께서는 dll이 너무 많아 복잡하다며 실행 파일 한개만을 원하셨다.
제프리 리쳐 형님과 같이 동적으로 어셈블리를 로드할까 했는데....좀 더 검색해보았다.
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { String resourceName = “AssemblyLoadingAndReflection.” + new AssemblyName(args.Name).Name + “.dll”; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { Byte[] assemblyData = new Byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } }; |
결국 Costumra.Fody 를 찾게 되었다.
자동으로 exe 안에 라이브러리를 넣어준다. 압축까지 지원해준다.
Nuget을 통하여 설치하면 "FodyWeavers.xml" 파일이 생성된다.
해당 xml 파일을 이용해 정교한 설정이 가능하다. (압축여부, Debug심볼첨부여부 등등...)
https://github.com/Fody/Costura
압축하였을 때는 .zip 확장자로 exe 파일에 삽입되어있다.
[압축하지 않은 상태]
[압축한 상태]