How to merge multiple assemblies into one?
You have several options:
- use ILMerge (free)
For howto see here and here
OR
- use some tool like SmartAssembly (commercial)
it can embed and merge among other things (no need to change your source code)
OR
- code that yourself in less than 10 lines (free but minimal source code change)
mark all needed dependencies as "embedded resource" - this way they are included in the EXE file... you need to setup anAssemblyResolve
handler which at runtime reads from Resources and returns the needed DLLs to the .NET runtime...
A great tool to include referenced assemblies as embedded resources is Costura (a Fody add-in). The author Simon Kropp describes it as follows:
[...] a combination of two methods:
- Jeffrey Richter's suggestion of using embedded resources as a method of merging assemblies
- Einar Egilsson's suggestion using cecil to create module initializers
The result is a super simple solution which merely requires to fetch Costura.Fody from NuGet.
Features:
- Including debug symbols
- Compression of embedded assemblies
- Including/excluding specific assemblies
- Others (see Readme)