Possible to merge a DLL into a .NET EXE? [duplicat

2019-01-14 09:56发布

问题:

This question already has an answer here:

  • Embedding DLLs in a compiled executable 19 answers

I have a DLL that stores classes common to two applications. I'd like to keep my application limited to one EXE file and would like to see if I can somehow embed this DLL within my main EXE.

How can I embed the external DLL into my application? (if possible)

回答1:

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=22914587-b4ad-4eae-87cf-b14ae6a939b0&displaylang=en

ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly. It works on executables and dlls alike. It comes with several options for controlling the processing and format of the output, see the accompanying documentation for details.



回答2:

An alternative to ILMerge is to embed dependent assemblies into the executable as embedded resouces and leverage the assembly resolve mechanism to load them as resource streams. An example of how to do this can be found here:

http://blog.magenic.com/blogs/brante/archive/2008/04/14/Embedded-Assembly-Linker.aspx

I use this pattern myself which works well. ILMerge sometimes has issues so your milage may vary.



回答3:

Eazfuscator.NET is a wonderful tool that also allows both dll merging AND embedding, as well as it's normal obfuscation functions. It also does some neat optimizing on obfuscated code. Instead of messing with ilmerge you just add one class annotation and eazfuscator will do everything for you. It's wonderful!

[assembly: System.Reflection.Obfuscation(Feature = "encrypt symbol names with password PAS$", Exclude = false)]
[assembly: System.Reflection.Obfuscation(Feature = "embed nLog.dll", Exclude = false)]
public class MyClass {
  //blah
}


标签: c# .net clr