How to combine several assemblies into one?

I use my service stack with an exe project (startup task for an azure application) in that I copied the following service stack dll and some azure dlls into an exe project.

dlls

When I create this EXE project, then the Azure DLLs will be associated with my EXE, but the service stack DLL stack will not be associated with the EXE, because in order to run my EXE on any computer I need to copy the entire stack DLL manually.

I used this service dll library to use

JsonServiceClient client = new JsonServiceClient(servicepath); 

What do I need to do to link all these DLLs in my EXE?

+68
exe c # servicestack assemblies ilmerge
Nov 10 2018-11-11T00:
source share
6 answers

You have several options:

OR

  • use some tool like SmartAssembly (commercial)
    it can be implemented and combined among other things (no need to change the source code).

OR

  • code that gives you at least 10 lines (free, but minimal source code)
    mark all the necessary dependencies as "built-in resource" - thus they are included in the EXE file ... you need to configure the AssemblyResolve handler which at runtime reads from the "Resources" and returns the necessary DLLs to the .NET runtime.
+93
Nov 10 2018-11-11T00:
source share

The tool you are looking for is called ILMerge . It is a command line tool and can be used as follows:

 ilmerge /target:winexe /out:MyApp.exe MyExe.exe ServiceStack.dll ServiceStack.Interfaces.dll ServiceStack.ServiceInterface.dll ServiceStack.Text.dll 

There is also an article that describes how to include ILMerge in setting up your VS project here

+25
Nov 10 '11 at 11:41
source share

A great tool for including referenced assemblies as embedded resources is Costura (add a Fody to). The author, Simon Kropp, describes this as follows:

[...] a combination of two methods:

The result is a super simple solution that just requires you to get Costura.Fody out of NuGet.

Features:

  • Including Debug Symbols
  • Embedded Assembly Compression
  • Including / excluding specific assemblies
  • Others (see Readme )
+18
Sep 23 '15 at 4:56
source share

Try ILMerge-GUI, .NET Merge . It is based on the Ilmerge , which avoids all work on the command line.

+5
Jun 26 '15 at 12:48
source share

Design the ServiceStack.Gap project, which shows several examples of how ILMerge ServiceStack is in one cross-platform .exe .

ServiceStack also includes a number of other features that are particularly suitable for creating embedded applications, where it:

  • Allows your services to host themselves using an HTTP HTTP listener.
  • Support for precompiled Razor views
  • Embedded Resource Support
  • Support for embedded database in Sqlite and OrmLite
  • Can be connected to a single .exe
+2
Jun 26 '15 at 13:12
source share

If you have WPF dependencies, your options may be more limited ... ILMerge doesn't seem to be able to handle them. Costura.Fody (as mentioned in Codefox above) did a great job for us and it took about 5 minutes to get through ... a very good experience.

Install using Nuget (choosing the correct default project in the package manager console).

It combines all the DLLs marked with Copy Local = true, and creates a combined .EXE (along with standard output, most of which are no longer required), which is also compressed. Then it can be used autonomously.

A license is an MIT, so you can modify / redistribute as needed.

https://github.com/Fody/Costura/

+2
Apr 13 '16 at 14:21
source share



All Articles